From: Dmitry Volyntsev Date: Fri, 12 Dec 2025 05:57:18 +0000 (-0800) Subject: HTTP: fixed buffer_type inheritance in if blocks. X-Git-Tag: 0.9.5~9 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=6b230aab765f7d6f2e9107bf2ca7164eac590039;p=njs.git HTTP: fixed buffer_type inheritance in if blocks. Previously, when js_body_filter was used inside an if block that evaluated to true, the data parameter received Buffer type instead of the expected String type. This happened because buffer_type field in ngx_http_js_loc_conf_t was not properly initialized, causing the configuration merge to fail when nginx created a new location context for if blocks. This fixes #999 issue on Github. --- diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index 8b38dbfd..63e55c80 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -8260,6 +8260,8 @@ ngx_http_js_create_loc_conf(ngx_conf_t *cf) conf->ssl_verify = NGX_CONF_UNSET; conf->ssl_verify_depth = NGX_CONF_UNSET; #endif + conf->buffer_type = NGX_CONF_UNSET_UINT; + return conf; } diff --git a/nginx/t/js_body_filter_if.t b/nginx/t/js_body_filter_if.t index af0aa865..dd9bc82f 100644 --- a/nginx/t/js_body_filter_if.t +++ b/nginx/t/js_body_filter_if.t @@ -58,6 +58,24 @@ http { proxy_pass http://127.0.0.1:8081/source; } + + location /type_check_true { + if ($arg_check) { + set $dummy 1; + } + + js_body_filter test.type_check; + proxy_pass http://127.0.0.1:8081/backend; + } + + location /type_check_false { + if ($arg_nonexistent = dummy) { + set $dummy 1; + } + + js_body_filter test.type_check; + proxy_pass http://127.0.0.1:8081/backend; + } } server { @@ -68,6 +86,10 @@ http { postpone_output 1; js_content test.source; } + + location /backend { + return 200 'payload'; + } } } @@ -113,15 +135,27 @@ $t->write_file('test.js', <try_run('no njs body filter')->plan(2); +$t->try_run('no njs body filter')->plan(4); ############################################################################### like(http_get('/filter?name=append'), qr/AAABBCDDDDXXX/, 'append'); like(http_get('/filter?name=prepend'), qr/XXXAAABBCDDDD/, 'prepend'); +like(http_get('/type_check_true?check=1'), qr/String: payload/, + 'type check with if block true'); +like(http_get('/type_check_false'), qr/String: payload/, + 'type check with if block false'); ###############################################################################