Bug 970121 Try to decode the URL in more cases r=Ratty SEA_2_26_1_RELBRANCH
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 21 Feb 2014 01:03:14 +0000
branchSEA_2_26_1_RELBRANCH
changeset 31069 fd910d1fd8f0a226948bb015d66069c45ca93cd9
parent 31068 3c60f4ed95d0966657820f4bff8e7c6c351f90c9
child 31070 6f6c5df761b9fdbdd4598d191a2affbeb3ba7858
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [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,
   // C0/C1 controls). (bug 452979, bug 909264)
   // 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