Bug 1067168 - Ipv4 with trailing slash input in locationbar should open the address, not perform a search. r=smaug

This commit is contained in:
Alex Bardas 2014-09-16 13:20:00 -04:00
parent fb74ad8c22
commit 47710df06a
2 changed files with 101 additions and 3 deletions

View File

@ -953,11 +953,13 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
// are found and a found before b.
uint32_t firstDotLoc = uint32_t(kNotFound);
uint32_t lastDotLoc = uint32_t(kNotFound);
uint32_t firstColonLoc = uint32_t(kNotFound);
uint32_t firstQuoteLoc = uint32_t(kNotFound);
uint32_t firstSpaceLoc = uint32_t(kNotFound);
uint32_t firstQMarkLoc = uint32_t(kNotFound);
uint32_t lastLSBracketLoc = uint32_t(kNotFound);
uint32_t lastSlashLoc = uint32_t(kNotFound);
uint32_t pos = 0;
uint32_t foundDots = 0;
uint32_t foundColons = 0;
@ -986,6 +988,7 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
}
if (*iter == '.') {
++foundDots;
lastDotLoc = pos;
if (firstDotLoc == uint32_t(kNotFound)) {
firstDotLoc = pos;
}
@ -1004,6 +1007,8 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
lastLSBracketLoc = pos;
} else if (*iter == ']') {
foundRSBrackets++;
} else if (*iter == '/') {
lastSlashLoc = pos;
} else if (nsCRT::IsAsciiAlpha(*iter)) {
hasAsciiAlpha = true;
} else if (nsCRT::IsAsciiDigit(*iter)) {
@ -1030,9 +1035,25 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetHost(host)) &&
!host.IsEmpty();
// If there are 3 dots and only numbers between them, then don't do a
// keyword lookup (ipv4)
if (foundDots == 3 && (foundDots + foundDigits == pos)) {
// 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;
}
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;
}

View File

@ -87,16 +87,93 @@ let testcases = [ {
input: "127.0.0.1",
fixedURI: "http://127.0.0.1/",
protocolChange: true,
}, {
input: "1.2.3.4/",
fixedURI: "http://1.2.3.4/",
protocolChange: true,
}, {
input: "1.2.3.4/foo",
fixedURI: "http://1.2.3.4/foo",
protocolChange: true,
}, {
input: "1.2.3.4:8000",
fixedURI: "http://1.2.3.4:8000/",
protocolChange: true,
}, {
input: "1.2.3.4:8000/",
fixedURI: "http://1.2.3.4:8000/",
protocolChange: true,
}, {
input: "1.2.3.4:8000/foo",
fixedURI: "http://1.2.3.4:8000/foo",
protocolChange: true,
}, {
input: "192.168.10.110",
fixedURI: "http://192.168.10.110/",
protocolChange: true,
}, {
input: "1.2.3",
fixedURI: "http://1.2.3/",
keywordLookup: true,
protocolChange: true,
}, {
input: "1.2.3/",
fixedURI: "http://1.2.3/",
protocolChange: true,
}, {
input: "1.2.3/foo",
fixedURI: "http://1.2.3/foo",
protocolChange: true,
}, {
input: "1.2.3:8000",
fixedURI: "http://1.2.3:8000/",
keywordLookup: true,
protocolChange: true,
}, {
input: "1.2.3:8000/",
fixedURI: "http://1.2.3:8000/",
protocolChange: true,
}, {
input: "1.2.3:8000/foo",
fixedURI: "http://1.2.3:8000/foo",
protocolChange: true,
}, {
input: "http://1.2.3",
fixedURI: "http://1.2.3/",
}, {
input: "http://1.2.3/",
fixedURI: "http://1.2.3/",
}, {
input: "http://1.2.3/foo",
fixedURI: "http://1.2.3/foo",
}, {
input: "[::1]",
fixedURI: "http://[::1]/",
alternateURI: "http://[::1]/",
protocolChange: true,
affectedByWhitelist: true
}, {
input: "[::1]/",
fixedURI: "http://[::1]/",
alternateURI: "http://[::1]/",
protocolChange: true,
affectedByWhitelist: true,
}, {
input: "[::1]:8000",
fixedURI: "http://[::1]:8000/",
alternateURI: "http://[::1]:8000/",
protocolChange: true,
affectedByWhitelist: true,
}, {
input: "[::1]:8000/",
fixedURI: "http://[::1]:8000/",
alternateURI: "http://[::1]:8000/",
protocolChange: true,
affectedByWhitelist: true,
}, {
input: "[[::1]]/",
keywordLookup: true,
protocolChange: true,
}, {
input: "[fe80:cd00:0:cde:1257:0:211e:729c]",
fixedURI: "http://[fe80:cd00:0:cde:1257:0:211e:729c]/",