Bug 970121 Try to decode the URL in more cases r=Ratty
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 21 Feb 2014 01:03:14 +0000
changeset 17596 ed8c317c7a96e15b4e3cd1e6d6e4748efe26606a
parent 17595 9cd7b9a9a86fcf4de1351cbf7748b9a0dcdf8e86
child 17597 01a9de9baf7a55d26935b0ac847518c2c2fda3f1
push id1175
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 08:37:15 +0000
treeherdercomm-aurora@3b5242ee031a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRatty
bugs970121
Bug 970121 Try to decode the URL in more cases r=Ratty
suite/browser/navigator.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -1964,27 +1964,29 @@ function URLBarSetURI(aURI, aValid) {
   getBrowser().userTypedValue = null;
 
   SetPageProxyState((value && (!aURI || aValid)) ? "valid" : "invalid", uri);
 }
 
 function losslessDecodeURI(aURI) {
   var value = aURI.spec;
   // Try to decode as UTF-8 if there's no encoding sequence that we would break.
-  if (!/%25(?:3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/i.test(value))
-    try {
-      value = decodeURI(value)
-                // decodeURI decodes %25 to %, which creates unintended
-                // encoding sequences. Re-encode it, unless it's part of
-                // a sequence that survived decodeURI, i.e. one for:
-                // ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#'
-                // (RFC 3987 section 3.2)
-                .replace(/%(?!3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/ig,
-                         encodeURIComponent);
-    } catch (e) {}
+  if (!/%25(?:3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/i.test(value)) {
+    const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
+                                   .getService(Components.interfaces.nsITextToSubURI);
+    var unescaped = textToSubURI.unEscapeURIForUI(aURI.originCharset, value);
+    // unEscapeURIForUI decodes %25 to %, which creates unintended
+    // encoding sequences. Re-encode it, unless it's part of
+    // a sequence that survived unEscapeURIForUI, i.e. one for:
+    // ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#'
+    // (RFC 3987 section 3.2)
+    if (unescaped != value)
+      value = unescaped.replace(/%(?!3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/ig,
+                                encodeURIComponent);
+  }
 
   // Encode invisible characters (soft hyphen, zero-width space, BOM,
   // line and paragraph separator, word joiner, invisible times,
   // invisible separator, object replacement character) (bug 452979)
   // Encode bidirectional formatting characters.
   // (RFC 3987 sections 3.2 and 4.1 paragraph 6)
   // Re-encode whitespace so that it doesn't get eaten away
   // by the location bar (bug 410726).