Bug 1420395 - deal with IDN domains without protocols correctly in nsIURIFixup, r=valentin

MozReview-Commit-ID: DZYnxExcqdp

--HG--
extra : rebase_source : 08b4cb23db26a09a3f6fbe8fd7ea79c4191b293e
This commit is contained in:
Gijs Kruitbosch 2017-11-28 14:28:58 +00:00
Родитель 76dc15b465
Коммит 5fb33f411d
2 изменённых файлов: 16 добавлений и 11 удалений

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

@ -924,17 +924,17 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
}
nsAutoCString asciiHost;
nsAutoCString host;
nsAutoCString displayHost;
bool isValidAsciiHost =
bool isValidHost =
aFixupInfo->mFixedURI &&
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetAsciiHost(asciiHost)) &&
!asciiHost.IsEmpty();
bool isValidHost =
bool isValidDisplayHost =
aFixupInfo->mFixedURI &&
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetHost(host)) &&
!host.IsEmpty();
NS_SUCCEEDED(aFixupInfo->mFixedURI->GetDisplayHost(displayHost)) &&
!displayHost.IsEmpty();
nsresult rv = NS_OK;
// We do keyword lookups if a space or quote preceded the dot, colon
@ -946,10 +946,10 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
firstQMarkLoc == 0) {
rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
aPostData);
// ... or when the host is the same as asciiHost and there are no
// ... or when the asciiHost is the same as displayHost and there are no
// characters from [a-z][A-Z]
} else if (isValidAsciiHost && isValidHost && !hasAsciiAlpha &&
host.EqualsIgnoreCase(asciiHost.get())) {
} else if (isValidHost && isValidDisplayHost && !hasAsciiAlpha &&
asciiHost.EqualsIgnoreCase(displayHost.get())) {
if (!sDNSFirstForSingleWords) {
rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
aPostData);
@ -962,7 +962,7 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
firstDotLoc == aURIString.Length() - 1))) &&
firstColonLoc == uint32_t(kNotFound) &&
firstQMarkLoc == uint32_t(kNotFound)) {
if (isValidAsciiHost && IsDomainWhitelisted(asciiHost, firstDotLoc)) {
if (isValidHost && IsDomainWhitelisted(asciiHost, firstDotLoc)) {
return NS_OK;
}
@ -970,7 +970,7 @@ nsDefaultURIFixup::KeywordURIFixup(const nsACString& aURIString,
// this is a valid host:
if (firstDotLoc == uint32_t(kNotFound) &&
lastSlashLoc != uint32_t(kNotFound) &&
hasAsciiAlpha && isValidAsciiHost) {
hasAsciiAlpha && isValidHost) {
return NS_OK;
}

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

@ -482,7 +482,12 @@ var testcases = [ {
input: "plonk:8080",
fixedURI: "http://plonk:8080/",
protocolChange: true,
}
}, {
input: "\u10E0\u10D4\u10D2\u10D8\u10E1\u10E2\u10E0\u10D0\u10EA\u10D8\u10D0.\u10D2\u10D4",
fixedURI: "http://xn--lodaehvb5cdik4g.xn--node/",
alternateURI: "http://www.xn--lodaehvb5cdik4g.xn--node/",
protocolChange: true,
},
];
if (Services.appinfo.OS.toLowerCase().startsWith("win")) {