Skip to content

Commit 615c296

Browse files
Extract PROTOCOL_SEPARATOR to companion object
1 parent f840b7e commit 615c296

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/src/main/java/com/infomaniak/mail/ui/newMessage/InsertLinkDialog.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,21 @@ class InsertLinkDialog @Inject constructor(
118118
}
119119

120120
private fun addMissingHttpsProtocol(link: String): String {
121-
val protocolEndIndex = link.indexOf("://")
121+
val protocolEndIndex = link.indexOf(PROTOCOL_SEPARATOR)
122122
val isProtocolSpecified = protocolEndIndex > 0 // If there is a specified protocol and it is at least 1 char long
123123

124124
if (isProtocolSpecified) return link
125125

126-
val strippedUserInput = if (protocolEndIndex != -1) link.substring(protocolEndIndex + 3) else link
126+
val strippedUserInput = if (protocolEndIndex == -1) link else link.substring(PROTOCOL_SEPARATOR.length)
127127

128128
return "https://$strippedUserInput"
129129
}
130130

131131
private fun validate(userUrlInput: String): Boolean {
132132
return Patterns.WEB_URL.matcher(userUrlInput).matches()
133133
}
134+
135+
companion object {
136+
private const val PROTOCOL_SEPARATOR = "://"
137+
}
134138
}

0 commit comments

Comments
 (0)