]> git.kaiwu.me - njs.git/commitdiff
Fixed querystring.parse().
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 6 Nov 2020 11:41:32 +0000 (11:41 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 6 Nov 2020 11:41:32 +0000 (11:41 +0000)
The issue happened when the first eq symbol is located after the
separator, whereas it should be looked for only in the string segment
before the separator.

This fixes #349 issue on Github.

src/njs_query_string.c
src/test/njs_unit_test.c

index b7743e9abbbc6e51e04345b22e9a3d57771a0171..7f8d6b1a7ac1f645dc8a8cfbc09c2a0efe25d777 100644 (file)
@@ -269,7 +269,7 @@ njs_query_string_match(u_char *p, u_char *end, njs_str_t *v)
         return p;
     }
 
-    while (p < (end - length)) {
+    while (p <= (end - length)) {
         if (memcmp(p, v->start, length) == 0) {
             return p;
         }
@@ -402,7 +402,7 @@ njs_query_string_parse(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
             goto next;
         }
 
-        val = njs_query_string_match(key, end, &eq);
+        val = njs_query_string_match(key, part, &eq);
 
         size = val - key;
 
index c48965c1b83dd5cc422b8f26bd4a7c60b895abce..0256d4a08ada00cddd76a4e247863151cbe78db6 100644 (file)
@@ -17986,6 +17986,11 @@ static njs_unit_test_t  njs_test[] =
               "njs.dump(obj)"),
       njs_str("{freespace:''}") },
 
+    { njs_str("var qs = require('querystring');"
+              "var obj = qs.parse('name&value=12');"
+              "njs.dump(obj)"),
+      njs_str("{name:'',value:'12'}") },
+
     { njs_str("var qs = require('querystring');"
               "var obj = qs.parse('baz=fuz&muz=tax', 'fuz');"
               "njs.dump(obj)"),