For #4844: fix file prefix url shortening
parent
957ed8aa88
commit
7477de83e9
|
@ -40,17 +40,12 @@ fun String.toShortUrl(publicSuffixList: PublicSuffixList): String {
|
|||
if (
|
||||
inputString.isEmpty() ||
|
||||
!URLUtil.isValidUrl(inputString) ||
|
||||
inputString == FILE_PREFIX ||
|
||||
inputString.startsWith(FILE_PREFIX) ||
|
||||
uri.port !in -1..MAX_VALID_PORT
|
||||
) {
|
||||
return inputString
|
||||
}
|
||||
|
||||
if (inputString.startsWith(FILE_PREFIX)) {
|
||||
// Strip file prefix and return the remainder
|
||||
return inputString.substring(FILE_PREFIX.length)
|
||||
}
|
||||
|
||||
if (uri.host?.isIpv4() == true ||
|
||||
uri.isIpv6() ||
|
||||
// If inputString is just a hostname and not a FQDN, use the entire hostname.
|
||||
|
|
|
@ -186,8 +186,8 @@ class StringTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `should return not the protocol for file`() {
|
||||
"file:///foo/bar.txt" shortenedShouldBecome "/foo/bar.txt"
|
||||
fun `file uri should return input`() {
|
||||
"file:///foo/bar.txt" shortenedShouldBecome "file:///foo/bar.txt"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue