Bug 1420395 - deal with IDN domains without protocols correctly in nsIURIFixup, r?valentin
MozReview-Commit-ID: DZYnxExcqdp
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -919,63 +919,63 @@ nsDefaultURIFixup::KeywordURIFixup(const
// 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;
+ 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
// or question mark (or if the latter is not found, or if the input starts
// with a question mark)
if (((firstSpaceLoc < firstDotLoc || firstQuoteLoc < firstDotLoc) &&
(firstSpaceLoc < firstColonLoc || firstQuoteLoc < firstColonLoc) &&
(firstSpaceLoc < firstQMarkLoc || firstQuoteLoc < firstQMarkLoc)) ||
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);
}
}
// ... or if there is no question mark or colon, and there is either no
// dot, or exactly 1 and it is the first or last character of the input:
else if ((firstDotLoc == uint32_t(kNotFound) ||
(foundDots == 1 && (firstDotLoc == 0 ||
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;
}
// ... unless there are no dots, and a slash, and alpha characters, and
// this is a valid host:
if (firstDotLoc == uint32_t(kNotFound) &&
lastSlashLoc != uint32_t(kNotFound) &&
- hasAsciiAlpha && isValidAsciiHost) {
+ hasAsciiAlpha && isValidHost) {
return NS_OK;
}
// If we get here, we don't have a valid URI, or we did but the
// host is not whitelisted, so we do a keyword search *anyway*:
rv = TryKeywordFixupForURIInfo(aFixupInfo->mOriginalInput, aFixupInfo,
aPostData);
}
--- a/docshell/test/unit/test_nsDefaultURIFixup_info.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -477,17 +477,22 @@ var testcases = [ {
}, {
input: "localhost:8080",
fixedURI: "http://localhost:8080/",
protocolChange: true,
}, {
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")) {
testcases.push({
input: "C:\\some\\file.txt",
fixedURI: "file:///C:/some/file.txt",
protocolChange: true,
});