[njs] Fixed querystring.parse().
Dmitry Volyntsev
xeioex at nginx.com
Fri Nov 6 11:42:28 UTC 2020
details: https://hg.nginx.org/njs/rev/3e7f9e326219
branches:
changeset: 1560:3e7f9e326219
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Nov 06 11:41:32 2020 +0000
description:
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.
diffstat:
src/njs_query_string.c | 4 ++--
src/test/njs_unit_test.c | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
diffs (36 lines):
diff -r 2d1abd2d38b4 -r 3e7f9e326219 src/njs_query_string.c
--- a/src/njs_query_string.c Tue Nov 03 15:31:41 2020 +0300
+++ b/src/njs_query_string.c Fri Nov 06 11:41:32 2020 +0000
@@ -269,7 +269,7 @@ njs_query_string_match(u_char *p, u_char
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
goto next;
}
- val = njs_query_string_match(key, end, &eq);
+ val = njs_query_string_match(key, part, &eq);
size = val - key;
diff -r 2d1abd2d38b4 -r 3e7f9e326219 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Nov 03 15:31:41 2020 +0300
+++ b/src/test/njs_unit_test.c Fri Nov 06 11:41:32 2020 +0000
@@ -17987,6 +17987,11 @@ static njs_unit_test_t njs_test[] =
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)"),
njs_str("{baz:'',&muz:'tax'}") },
More information about the nginx-devel
mailing list