]> git.kaiwu.me - njs.git/commit
Querystring: fix decoding after invalid UTF-8 master
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 14 Nov 2026 02:37:35 +0000 (18:37 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Sat, 14 Nov 2026 05:31:46 +0000 (21:31 -0800)
commit2786bd98a5363849f5641b624469251800e677f0
tree23fd79e1a1175640065ebc1a6054ad547dc17515
parentaeb779b531822b917984f5b741c918d4cc4d338a
Querystring: fix decoding after invalid UTF-8

Previously, percent-decoding advanced past each encoded byte even when
the UTF-8 decoder left it unconsumed after reporting an invalid pending
sequence.  For example, "%D8%41%42" decoded to "\ufffdB" instead of
"\ufffdAB".  This affected querystring.parse() and unescape() in both
engines, and r.args in nginx.

Now njs_utf8_consume() reports whether the byte was consumed, so callers
can reread it before advancing the input, as the WHATWG UTF-8 decoder
requires.  Plus signs are also passed through the decoder as spaces,
so they flush invalid pending sequences without losing or reordering
the replacement character.

The issue was introduced in 50ea0dbc (0.4.3), copied into QuickJS
r.args in 201b1276 (0.8.6) and into its querystring module in f289dcb9
(0.8.10).
external/njs_query_string_module.c
external/qjs_query_string_module.c
nginx/ngx_http_js_module.c
nginx/t/js_args.t
src/njs_utf8.h
test/querystring.t.mjs