Bug 1064481 - URLSearchParams should encode % values correcty. r=ehsan, a=lmandel
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 08 Sep 2014 19:27:00 -0400
changeset 216773 f44f06112715
parent 216772 dafe68644b45
child 216774 023a362fab21
push id3908
push userryanvm@gmail.com
push date2014-09-17 21:11 +0000
treeherdermozilla-beta@f44f06112715 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lmandel
bugs1064481
milestone33.0
Bug 1064481 - URLSearchParams should encode % values correcty. r=ehsan, a=lmandel
dom/base/URLSearchParams.cpp
dom/base/test/mochitest.ini
dom/base/test/test_bug1064481.html
--- a/dom/base/URLSearchParams.cpp
+++ b/dom/base/URLSearchParams.cpp
@@ -295,17 +295,17 @@ public:
         mValue.Append(0x2B);
       // Percent Encode algorithm
       } else if (*p == 0x2A || *p == 0x2D || *p == 0x2E ||
                  (*p >= 0x30 && *p <= 0x39) ||
                  (*p >= 0x41 && *p <= 0x5A) || *p == 0x5F ||
                  (*p >= 0x61 && *p <= 0x7A)) {
         mValue.Append(*p);
       } else {
-        mValue.AppendPrintf("%%%X", *p);
+        mValue.AppendPrintf("%%%.2X", *p);
       }
 
       ++p;
     }
   }
 };
 
 void
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -15,16 +15,17 @@ support-files =
 [test_audioNotification.html]
 [test_bug793311.html]
 [test_bug913761.html]
 [test_bug976673.html]
 [test_bug978522.html]
 [test_bug979109.html]
 [test_bug989665.html]
 [test_bug999456.html]
+[test_bug1064481.html]
 [test_clearTimeoutIntervalNoArg.html]
 [test_consoleEmptyStack.html]
 [test_constructor-assignment.html]
 [test_constructor.html]
 [test_dialogArguments.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s
 [test_document.all_unqualified.html]
 [test_domcursor.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_bug1064481.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1064481
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1064481</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1064481">Mozilla Bug 1064481</a>
+  <iframe id="iframe"></iframe>
+  <script type="application/javascript">
+
+var a = new URLSearchParams();
+
+a.set('foobar', 'a\nb');
+is(a.toString(), 'foobar=a%0Ab', "Bug fixed");
+
+  </script>
+</body>
+</html>