querystring: remove prepended ? from query field
authorEzequiel Rabinovich <erabinovich@gmail.com>
Wed, 13 Aug 2014 02:32:22 +0000 (23:32 -0300)
committerTrevor Norris <trev.norris@gmail.com>
Wed, 13 Aug 2014 03:38:30 +0000 (20:38 -0700)
Fixes an issue that caused the first querystring to be parsed prepending
a "?" in the first variable name on relative urls with no #fragment

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib/url.js
test/simple/test-url.js

index f0be09c52d1d3511c05492f3223f2c3ac82958aa..ec417a8aa41f3bcc3033670323d6ff7eccb9a023 100644 (file)
@@ -132,7 +132,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
       if (simplePath[2]) {
         this.search = simplePath[2];
         if (parseQueryString) {
-          this.query = querystring.parse(this.search);
+          this.query = querystring.parse(this.search.substr(1));
         } else {
           this.query = this.search.substr(1);
         }
index cb39844827a9e4000f584e867983363453aa519f..3271b0ba21addd631c98041f723960ebdba5cd56 100644 (file)
@@ -867,6 +867,20 @@ var parseTestsWithQueryString = {
     'search': '',
     'pathname': '/',
     'path': '/'
+  },
+  '/example?query=value':{
+    protocol: null,
+    slashes: null,
+    auth: null,
+    host: null,
+    port: null,
+    hostname: null,
+    hash: null,
+    search: '?query=value',
+    query: { query: 'value' },
+    pathname: '/example',
+    path: '/example?query=value',
+    href: '/example?query=value'
   }
 };
 for (var u in parseTestsWithQueryString) {