Welcome! Log In Create A New Profile

Advanced

[njs] Fixed querystring.parse().

Dmitry Volyntsev
November 06, 2020 06:44AM
details: https://hg.nginx.org/njs/rev/3e7f9e326219
branches:
changeset: 1560:3e7f9e326219
user: Dmitry Volyntsev <xeioex@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'}") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed querystring.parse().

Dmitry Volyntsev 79 November 06, 2020 06:44AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready