Skip to content

Commit

Permalink
Bug 1623222 - Remove the charset parameter from nsITextToSubURI::UnEs…
Browse files Browse the repository at this point in the history
…capeURIForUI. r=hsivonen

Only 3 callers are using a non-UTF-8 charset as the first parameter.
* MediaDocument.cpp: This does not make sense because the "filename" part of
  URLs will always be encoded with UTF-8.
* nsContextMenu.js: This is wrong because "mailto:" URLs don't care about the
  document charset.
* Finder.jsm: This caused bug 1623222.

Differential Revision: https://phabricator.services.mozilla.com/D67386
  • Loading branch information
vyv03354 committed Mar 19, 2020
1 parent be1f4dc commit 68393a8
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 54 deletions.
2 changes: 1 addition & 1 deletion browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5018,7 +5018,7 @@ var XULBrowserWindow = {

setOverLink(url) {
if (url) {
url = Services.textToSubURI.unEscapeURIForUI("UTF-8", url);
url = Services.textToSubURI.unEscapeURIForUI(url);

// Encode bidirectional formatting characters.
// (RFC 3987 sections 3.2 and 4.1 paragraph 6)
Expand Down
5 changes: 1 addition & 4 deletions browser/base/content/nsContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1686,10 +1686,7 @@ class nsContextMenu {
// Let's try to unescape it using a character set
// in case the address is not ASCII.
try {
addresses = Services.textToSubURI.unEscapeURIForUI(
this.contentData.charSet,
addresses
);
addresses = Services.textToSubURI.unEscapeURIForUI(addresses);
} catch (ex) {
// Do nothing.
}
Expand Down
5 changes: 1 addition & 4 deletions browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ function makeUrlbarResult(tokens, info) {
if (!title) {
// If the url doesn't have an host (e.g. javascript urls), comment
// will be empty, and we can't build the usual title. Thus use the url.
title = Services.textToSubURI.unEscapeURIForUI(
"UTF-8",
action.params.url
);
title = Services.textToSubURI.unEscapeURIForUI(action.params.url);
} else if (tokens && tokens.length > 1) {
title = UrlbarUtils.strings.formatStringFromName(
"bookmarkKeywordSearch",
Expand Down
5 changes: 1 addition & 4 deletions browser/components/urlbar/UrlbarResult.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ class UrlbarResult {
url = BrowserUtils.trimURL(url);
}
}
payloadInfo.displayUrl[0] = Services.textToSubURI.unEscapeURIForUI(
"UTF-8",
url
);
payloadInfo.displayUrl[0] = Services.textToSubURI.unEscapeURIForUI(url);
}

// For performance reasons limit excessive string lengths, to reduce the
Expand Down
3 changes: 1 addition & 2 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3939,8 +3939,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
rv = textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"), spec,
nextFormatStr);
rv = textToSubURI->UnEscapeURIForUI(spec, nextFormatStr);
}
} else {
spec.Assign('?');
Expand Down
7 changes: 2 additions & 5 deletions dom/html/MediaDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,12 @@ void MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel) {
url->GetFileName(fileName);
if (fileName.IsEmpty()) return;

nsAutoCString docCharset;
// Now that the charset is set in |StartDocumentLoad| to the charset of
// the document viewer instead of a bogus value ("windows-1252" set in
// |Document|'s ctor), the priority is given to the current charset.
// This is necessary to deal with a media document being opened in a new
// window or a new tab.
if (mCharacterSetSource != kCharsetUninitialized) {
mCharacterSet->Name(docCharset);
} else {
if (mCharacterSetSource == kCharsetUninitialized) {
// resort to UTF-8
SetDocumentCharacterSet(UTF_8_ENCODING);
}
Expand All @@ -276,7 +273,7 @@ void MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel) {
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
// UnEscapeURIForUI always succeeds
textToSubURI->UnEscapeURIForUI(docCharset, fileName, aResult);
textToSubURI->UnEscapeURIForUI(fileName, aResult);
} else {
CopyUTF8toUTF16(fileName, aResult);
}
Expand Down
7 changes: 3 additions & 4 deletions intl/uconv/nsITextToSubURI.idl
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ interface nsITextToSubURI : nsISupports
* <ul>
* <li> escaping back the result (unescaped string) is not guaranteed to
* give the original escaped string
* <li> In case of a conversion error, the URI fragment (escaped) is
* assumed to be in UTF-8 and converted to AString (UTF-16)
* <li> The URI fragment (escaped) is assumed to be in UTF-8 and converted
* to AString (UTF-16)
* <li> In case of successful conversion any resulting character listed
* in netwerk/dns/IDNCharacterBlocklist.inc (except space) is escaped
* <li> Always succeeeds (callers don't need to do error checking)
* </ul>
*
* @param aCharset the charset to convert from
* @param aURIFragment the URI (or URI fragment) to unescape
* @return Unescaped aURIFragment converted to unicode
*/
AString unEscapeURIForUI(in ACString aCharset, in AUTF8String aURIFragment);
AString unEscapeURIForUI(in AUTF8String aURIFragment);

/**
* Unescapes only non ASCII characters in the given URI fragment
Expand Down
5 changes: 2 additions & 3 deletions intl/uconv/nsTextToSubURI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ nsresult nsTextToSubURI::convertURItoUnicode(const nsCString& aCharset,
return encoding->DecodeWithoutBOMHandlingAndWithoutReplacement(aURI, aOut);
}

NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aCharset,
const nsACString& aURIFragment,
NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aURIFragment,
nsAString& _retval) {
nsAutoCString unescapedSpec;
// skip control octets (0x00 - 0x1f and 0x7f) when unescaping
Expand All @@ -112,7 +111,7 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aCharset,
// in case of failure, return escaped URI
// Test for != NS_OK rather than NS_FAILED, because incomplete multi-byte
// sequences are also considered failure in this context
if (convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec,
if (convertURItoUnicode(NS_LITERAL_CSTRING("UTF-8"), unescapedSpec,
_retval) != NS_OK) {
// assume UTF-8 instead of ASCII because hostname (IDN) may be in UTF-8
CopyUTF8toUTF16(aURIFragment, _retval);
Expand Down
3 changes: 1 addition & 2 deletions layout/printing/nsPrintJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,7 @@ void nsPrintJob::GetDisplayTitleAndURL(Document& aDoc,
return;
}

textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"), urlCStr,
aURLStr);
textToSubURI->UnEscapeURIForUI(urlCStr, aURLStr);
}
}

Expand Down
3 changes: 1 addition & 2 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2684,8 +2684,7 @@ nsresult NS_GetFilenameFromDisposition(nsAString& aFilename,
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoString unescaped;
textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"),
NS_ConvertUTF16toUTF8(aFilename),
textToSubURI->UnEscapeURIForUI(NS_ConvertUTF16toUTF8(aFilename),
unescaped);
aFilename.Assign(unescaped);
}
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/extensions/parent/ext-downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ this.downloads = class extends ExtensionAPI {
let uri = Services.io.newURI(options.url);
if (uri instanceof Ci.nsIURL) {
filename = DownloadPaths.sanitize(
Services.textToSubURI.unEscapeURIForUI("UTF-8", uri.fileName)
Services.textToSubURI.unEscapeURIForUI(uri.fileName)
);
}
}
Expand Down
6 changes: 1 addition & 5 deletions toolkit/components/places/UnifiedComplete.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ function Search(
this._originalSearchString = searchString;
this._trimmedOriginalSearchString = searchString.trim();
let unescapedSearchString = Services.textToSubURI.unEscapeURIForUI(
"UTF-8",
this._trimmedOriginalSearchString
);
let [prefix, suffix] = stripPrefix(unescapedSearchString);
Expand Down Expand Up @@ -2050,10 +2049,7 @@ Search.prototype = {
// to be displayed to the user, and in any case the front-end should not
// rely on it being canonical.
let escapedURL = uri.displaySpec;
let displayURL = Services.textToSubURI.unEscapeURIForUI(
"UTF-8",
escapedURL
);
let displayURL = Services.textToSubURI.unEscapeURIForUI(escapedURL);

let value = makeActionUrl("visiturl", {
url: escapedURL,
Expand Down
6 changes: 2 additions & 4 deletions toolkit/content/contentAreaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,7 @@ function getDefaultFileName(
} catch (e) {}
}
if (fileName) {
return validateFileName(
Services.textToSubURI.unEscapeURIForUI("UTF-8", fileName)
);
return validateFileName(Services.textToSubURI.unEscapeURIForUI(fileName));
}
}

Expand All @@ -1227,7 +1225,7 @@ function getDefaultFileName(
if (url.fileName != "") {
// 3) Use the actual file name, if present
return validateFileName(
Services.textToSubURI.unEscapeURIForUI("UTF-8", url.fileName)
Services.textToSubURI.unEscapeURIForUI(url.fileName)
);
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion toolkit/content/widgets/autocomplete-richlistitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
}

_unescapeUrl(url) {
return Services.textToSubURI.unEscapeURIForUI("UTF-8", url);
return Services.textToSubURI.unEscapeURIForUI(url);
}

_reuseAcItem() {
Expand Down
11 changes: 1 addition & 10 deletions toolkit/modules/Finder.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,7 @@ Finder.prototype = {
let foundLink = this._fastFind.foundLink;
let linkURL = null;
if (foundLink) {
let docCharset = null;
let ownerDoc = foundLink.ownerDocument;
if (ownerDoc) {
docCharset = ownerDoc.characterSet;
}

linkURL = Services.textToSubURI.unEscapeURIForUI(
docCharset,
foundLink.href
);
linkURL = Services.textToSubURI.unEscapeURIForUI(foundLink.href);
}

options.linkURL = linkURL;
Expand Down
3 changes: 1 addition & 2 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ static nsresult UnescapeFragment(const nsACString& aFragment, nsIURI* aURI,
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);

return textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"), aFragment,
aResult);
return textToSubURI->UnEscapeURIForUI(aFragment, aResult);
}

/**
Expand Down

0 comments on commit 68393a8

Please sign in to comment.