Bug 1154245 - non-alpha paths on IP addresses with no protocol shouldn't trigger search, r=smaug

--HG--
extra : rebase_source : 8bd586b23bb56cfc26aed4f885ecee6f207d4cc1
This commit is contained in:
Gijs Kruitbosch 2015-04-18 12:20:42 +01:00
Родитель 284cbc74c1
Коммит 7f9da983fa
2 изменённых файлов: 47 добавлений и 32 удалений

Просмотреть файл

@ -967,6 +967,23 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
looksLikeIpv6 = false;
}
}
// If we're at the end of the string or this is the first slash,
// check if the thing before the slash looks like ipv4:
if ((iter.size_forward() == 1 || (lastSlashLoc == uint32_t(kNotFound) && *iter == '/')) &&
// Need 2 or 3 dots + only digits
(foundDots == 2 || foundDots == 3) &&
// and they should be all that came before now:
(foundDots + foundDigits == pos ||
// or maybe there was also exactly 1 colon that came after the last dot,
// and the digits, dots and colon were all that came before now:
(foundColons == 1 && firstColonLoc > lastDotLoc &&
foundDots + foundDigits + foundColons == pos))) {
// Hurray, we got ourselves some ipv4!
// At this point, there's no way we will do a keyword lookup, so just bail immediately:
return NS_OK;
}
if (*iter == '.') {
++foundDots;
lastDotLoc = pos;
@ -1005,6 +1022,12 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
looksLikeIpv6 = false;
}
// If there are only colons and only hexadecimal characters ([a-z][0-9])
// enclosed in [], then don't do a keyword lookup
if (looksLikeIpv6) {
return NS_OK;
}
nsAutoCString asciiHost;
nsAutoCString host;
@ -1018,34 +1041,6 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetHost(host)) &&
!host.IsEmpty();
// If there are 2 dots and only numbers between them, an optional port number
// and a trailing slash, then don't do a keyword lookup
if (foundDots == 2 && lastSlashLoc == pos - 1 &&
((foundDots + foundDigits == pos - 1) ||
(foundColons == 1 && firstColonLoc > lastDotLoc &&
foundDots + foundDigits + foundColons == pos - 1))) {
return NS_OK;
}
uint32_t posWithNoTrailingSlash = pos;
if (lastSlashLoc == pos - 1) {
posWithNoTrailingSlash -= 1;
}
// If there are 3 dots and only numbers between them, an optional port number
// and an optional trailling slash, then don't do a keyword lookup (ipv4)
if (foundDots == 3 &&
((foundDots + foundDigits == posWithNoTrailingSlash) ||
(foundColons == 1 && firstColonLoc > lastDotLoc &&
foundDots + foundDigits + foundColons == posWithNoTrailingSlash))) {
return NS_OK;
}
// If there are only colons and only hexadecimal characters ([a-z][0-9])
// enclosed in [], then don't do a keyword lookup
if (looksLikeIpv6) {
return NS_OK;
}
nsresult rv = NS_OK;
// We do keyword lookups if a space or quote preceded the dot, colon
// or question mark (or if the latter is not found, or if the input starts

Просмотреть файл

@ -114,12 +114,26 @@ let testcases = [ {
input: "192.168.10.110",
fixedURI: "http://192.168.10.110/",
protocolChange: true,
}, {
input: "192.168.10.110/123",
fixedURI: "http://192.168.10.110/123",
protocolChange: true,
}, {
input: "192.168.10.110/123foo",
fixedURI: "http://192.168.10.110/123foo",
protocolChange: true,
}, {
input: "192.168.10.110:1234/123",
fixedURI: "http://192.168.10.110:1234/123",
protocolChange: true,
}, {
input: "192.168.10.110:1234/123foo",
fixedURI: "http://192.168.10.110:1234/123foo",
protocolChange: true,
}, {
input: "1.2.3",
fixedURI: "http://1.2.3/",
keywordLookup: true,
protocolChange: true,
affectedByDNSForSingleHosts: true,
}, {
input: "1.2.3/",
fixedURI: "http://1.2.3/",
@ -128,12 +142,14 @@ let testcases = [ {
input: "1.2.3/foo",
fixedURI: "http://1.2.3/foo",
protocolChange: true,
}, {
input: "1.2.3/123",
fixedURI: "http://1.2.3/123",
protocolChange: true,
}, {
input: "1.2.3:8000",
fixedURI: "http://1.2.3:8000/",
keywordLookup: true,
protocolChange: true,
affectedByDNSForSingleHosts: true,
}, {
input: "1.2.3:8000/",
fixedURI: "http://1.2.3:8000/",
@ -142,6 +158,10 @@ let testcases = [ {
input: "1.2.3:8000/foo",
fixedURI: "http://1.2.3:8000/foo",
protocolChange: true,
}, {
input: "1.2.3:8000/123",
fixedURI: "http://1.2.3:8000/123",
protocolChange: true,
}, {
input: "http://1.2.3",
fixedURI: "http://1.2.3/",