1
0
Fork 0

For #4844: fix file prefix url shortening

master
Severin Rudie 2019-12-09 10:46:24 -08:00 committed by Emily Kager
parent 957ed8aa88
commit 7477de83e9
2 changed files with 3 additions and 8 deletions

View File

@ -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.

View File

@ -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