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