From: Dmitry Volyntsev Date: Fri, 6 Nov 2020 11:41:32 +0000 (+0000) Subject: Fixed querystring.parse(). X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=489909301db250c06d7a38a95e03bcdba56095ff;p=njs.git Fixed querystring.parse(). 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. --- diff --git a/src/njs_query_string.c b/src/njs_query_string.c index b7743e9a..7f8d6b1a 100644 --- a/src/njs_query_string.c +++ b/src/njs_query_string.c @@ -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; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index c48965c1..0256d4a0 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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)"),