Bug 473822 - Square brackets not percent-encoded in URI's query-part. r=jduell
authorValentin Gosu <valentin.gosu@gmail.com>
Sat, 06 Sep 2014 01:32:04 +0300
changeset 228781 cc192030c28fa60a6db2041c852ea82a1b89a2c0
parent 228780 654b0c2a09135aeed35f1527572a078e4d688fbf
child 228782 6f39909c5bdad28470203909cb42d7905d66fcc0
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs473822
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 473822 - Square brackets not percent-encoded in URI's query-part. r=jduell
netwerk/test/unit/test_standardurl.js
xpcom/io/nsEscape.cpp
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -215,17 +215,33 @@ function test_clearedSpec()
   Assert.throws(() => { url.spec = ""; }, "set empty spec");
   do_check_eq(url.spec, "http://example.com/path");
   url.host = "allizom.org";
 
   var ref = stringToURL("http://allizom.org/path");
   symmetricEquality(true, url, ref);
 }
 
+function test_escapeQueryBrackets()
+{
+  var url = stringToURL("http://example.com/?a[x]=1");
+  do_check_eq(url.spec, "http://example.com/?a%5Bx%5D=1");
+
+  url = stringToURL("http://example.com/?a%5Bx%5D=1");
+  do_check_eq(url.spec, "http://example.com/?a%5Bx%5D=1");
+
+  url = stringToURL("http://[2001::1]/?a[x]=1");
+  do_check_eq(url.spec, "http://[2001::1]/?a%5Bx%5D=1");
+
+  url = stringToURL("http://[2001::1]/?a%5Bx%5D=1");
+  do_check_eq(url.spec, "http://[2001::1]/?a%5Bx%5D=1");
+}
+
 function run_test()
 {
   test_setEmptyPath();
   test_setQuery();
   test_setRef();
   test_ipv6();
   test_ipv6_fail();
   test_clearedSpec();
+  test_escapeQueryBrackets();
 }
--- a/xpcom/io/nsEscape.cpp
+++ b/xpcom/io/nsEscape.cpp
@@ -314,17 +314,17 @@ nsEscapeHTML2(const char16_t* aSourceBuf
 const int EscapeChars[256] =
 /*   0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
 {
      0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  /* 0x */
      0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  /* 1x */
      0,1023,   0, 512,1023,   0,1023,   0,1023,1023,1023,1023,1023,1023, 953, 784,  /* 2x   !"#$%&'()*+,-./  */
   1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1008,1008,   0,1008,   0, 768,  /* 3x  0123456789:;<=>?  */
   1008,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,  /* 4x  @ABCDEFGHIJKLMNO  */
-  1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 896, 896,1023,  /* 5x  PQRSTUVWXYZ[\]^_  */
+  1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,   0, 896,   0, 896,1023,  /* 5x  PQRSTUVWXYZ[\]^_  */
      0,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,  /* 6x  `abcdefghijklmno  */
   1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896,1012, 896,1023,   0,  /* 7x  pqrstuvwxyz{|}~   */
      0    /* 8x  DEL               */
 };
 
 #define NO_NEED_ESC(C) (EscapeChars[((unsigned int)(C))] & (aFlags))
 
 //----------------------------------------------------------------------------------------