diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index aa34a76c1d98..e40fc1617e8b 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2285,9 +2285,15 @@ function getShortcutOrURI(aURL, aPostDataRef) { } catch (e) {} } + // encodeURIComponent produces UTF-8, and cannot be used for other charsets. + // escape() works in those cases, but it doesn't uri-encode +, @, and /. + // Therefore we need to manually replace these ASCII characters by their + // encodeURIComponent result, to match the behavior of nsEscape() with + // url_XPAlphas var encodedParam = ""; - if (charset) - encodedParam = escape(convertFromUnicode(charset, param)); + if (charset && charset != "UTF-8") + encodedParam = escape(convertFromUnicode(charset, param)). + replace(/[+@\/]+/g, encodeURIComponent); else // Default charset is UTF-8 encodedParam = encodeURIComponent(param); diff --git a/browser/base/content/test/browser_getshortcutoruri.js b/browser/base/content/test/browser_getshortcutoruri.js index 1b319ded812d..d4726b72e6f5 100644 --- a/browser/base/content/test/browser_getshortcutoruri.js +++ b/browser/base/content/test/browser_getshortcutoruri.js @@ -74,6 +74,14 @@ var testData = [ // Explicitly-defined ISO-8859-1 [new bmKeywordData("bmget-escaping2", "http://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1", null, "foé"), new keywordResult("http://bmget/?esc=fo%E9&raw=foé", null)], + + // Bug 359809: Test escaping +, /, and @ + // UTF-8 default + [new bmKeywordData("bmget-escaping", "http://bmget/?esc=%s&raw=%S", null, "+/@"), + new keywordResult("http://bmget/?esc=%2B%2F%40&raw=+/@", null)], + // Explicitly-defined ISO-8859-1 + [new bmKeywordData("bmget-escaping2", "http://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1", null, "+/@"), + new keywordResult("http://bmget/?esc=%2B%2F%40&raw=+/@", null)], ]; function test() {