Bug 427304 Cannot search with non-ascii characters (nsURLFormatter wrongly parses encoded uri) p=Kohei Yoshino<kohei.yoshino.bugs@gmail.com>, r=gavin, a1.9=beltzner
authormasayuki@d-toybox.com
Wed, 23 Apr 2008 00:42:30 -0700
changeset 14610 ab2b23999d09f75e9773725720b0fa2520a8cbed
parent 14609 a574d346fbc45b2cb757e3349e4834ae5c34ed08
child 14611 7f36918e86d47f8dcab6ce2b786002488bb84fdd
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs427304
milestone1.9pre
Bug 427304 Cannot search with non-ascii characters (nsURLFormatter wrongly parses encoded uri) p=Kohei Yoshino<kohei.yoshino.bugs@gmail.com>, r=gavin, a1.9=beltzner
toolkit/components/urlformatter/src/nsURLFormatter.js
toolkit/components/urlformatter/tests/unit/test_urlformatter.js
--- a/toolkit/components/urlformatter/src/nsURLFormatter.js
+++ b/toolkit/components/urlformatter/src/nsURLFormatter.js
@@ -82,17 +82,17 @@ nsURLFormatterService.prototype = {
   },
 
   formatURL: function uf_formatURL(aFormat) {
     var _this = this;
     var replacementCallback = function(aMatch, aKey) {
       if (aKey in _this._defaults) // supported defaults
         return _this._defaults[aKey]();
       Cu.reportError("formatURL: Couldn't find value for key: " + aKey);
-      return '';
+      return aMatch;
     }
     return aFormat.replace(/%([A-Z]+)%/g, replacementCallback);
   },
 
   formatURLPref: function uf_formatURLPref(aPref) {
     var format = null;
     var PS = Cc['@mozilla.org/preferences-service;1'].
              getService(Ci.nsIPrefBranch);
--- a/toolkit/components/urlformatter/tests/unit/test_urlformatter.js
+++ b/toolkit/components/urlformatter/tests/unit/test_urlformatter.js
@@ -43,21 +43,25 @@ function run_test() {
               getService(Ci.nsIPrefBranch);
 
   var upperUrlRaw = "http://%LOCALE%.%VENDOR%.foo/?name=%NAME%&id=%ID%&version=%VERSION%&platversion=%PLATFORMVERSION%&abid=%APPBUILDID%&pbid=%PLATFORMBUILDID%&app=%APP%&os=%OS%&abi=%XPCOMABI%";
   var lowerUrlRaw = "http://%locale%.%vendor%.foo/?name=%name%&id=%id%&version=%version%&platversion=%platformversion%&abid=%appbuildid%&pbid=%platformbuildid%&app=%app%&os=%os%&abi=%xpcomabi%";
   //XXX %APP%'s RegExp is not global, so it only replaces the first space
   var ulUrlRef = "http://" + locale + ".Mozilla.foo/?name=Url Formatter Test&id=urlformattertest@test.mozilla.org&version=1&platversion=2.0&abid=2007122405&pbid=2007122406&app=urlformatter test&os=XPCShell&abi=noarch-spidermonkey";
   var multiUrl = "http://%VENDOR%.%VENDOR%.%NAME%.%VENDOR%.%NAME%";
   var multiUrlRef = "http://Mozilla.Mozilla.Url Formatter Test.Mozilla.Url Formatter Test";
+  var encodedUrl = "https://%LOCALE%.%VENDOR%.foo/?q=%E3%82%BF%E3%83%96&app=%name%&ver=%PLATFORMVERSION%";
+  var encodedUrlRef = "https://" + locale + ".Mozilla.foo/?q=%E3%82%BF%E3%83%96&app=Url Formatter Test&ver=2.0";
 
   var pref = "xpcshell.urlformatter.test";
   var str = Cc["@mozilla.org/supports-string;1"].
             createInstance(Ci.nsISupportsString);
   str.data = upperUrlRaw;
   prefs.setComplexValue(pref, Ci.nsISupportsString, str);
 
   do_check_eq(formatter.formatURL(upperUrlRaw), ulUrlRef);
   do_check_eq(formatter.formatURLPref(pref), ulUrlRef);
   // Keys must be uppercase
   do_check_neq(formatter.formatURL(lowerUrlRaw), ulUrlRef);
   do_check_eq(formatter.formatURL(multiUrl), multiUrlRef);
+  // Encoded strings must be kept as is (Bug 427304)
+  do_check_eq(formatter.formatURL(encodedUrl), encodedUrlRef);
 }