@@ -9,7 +9,9 @@ log_level('warn');
99repeat_each(2 );
1010# repeat_each(1);
1111
12- plan tests => repeat_each() * (blocks() * 2 + 21 );
12+
13+ plan tests => repeat_each() * (blocks() * 2 + 23 );
14+
1315
1416no_root_location();
1517
@@ -1579,7 +1581,7 @@ args: foo=%2C%24%40%7C%60&bar=-_.!~*'()
15791581 location / t {
15801582 content_by_lua_block {
15811583 local new_uri = ' \0foo'
1582- ngx. req. set_uri(new_uri)
1584+ ngx. req. set_uri(new_uri, false, true )
15831585 ngx. say (ngx. var. uri)
15841586 }
15851587 }
@@ -1684,3 +1686,84 @@ bad argument #1 to 'set_uri_args' (string, number, or table expected, but got ni
16841686-- - error_code: 500
16851687-- - error_log
16861688bad argument # 1 to 'set_uri_args' (string, number, or table expected, but got userdata)
1689+
1690+
1691+
1692+ === TEST 64 : set_uri binary option with unsafe uri
1693+ explict specify binary option to true
1694+ -- - config
1695+ location / t {
1696+ rewrite_by_lua_block {
1697+ local new_uri = " /foo\r\n bar"
1698+ ngx. req. set_uri(new_uri, false, true)
1699+ }
1700+
1701+ proxy_pass http: // 127.0 . 0. 1: $ TEST_NGINX_SERVER_PORT ;
1702+ }
1703+
1704+ location / foo {
1705+ content_by_lua_block {
1706+ ngx. say (" request_uri: " , ngx. var. request_uri)
1707+ ngx. say (" uri: " , ngx. var. uri)
1708+ }
1709+ }
1710+ -- - request
1711+ GET / t
1712+ -- - response_body eval
1713+ [" request_uri: /foo%0D%0Abar\n uri: /foo\r\n bar\n " , " request_uri: /foo%0D%0Abar\n uri: /foo\r\n bar\n " ]
1714+ -- - no_error_log
1715+ [error]
1716+
1717+
1718+
1719+ === TEST 65 : set_uri binary option with unsafe uri
1720+ explict specify binary option to false
1721+ -- - config
1722+ location / t {
1723+ rewrite_by_lua_block {
1724+ local new_uri = " /foo\r\n bar"
1725+ ngx. req. set_uri(new_uri, false, false)
1726+ }
1727+
1728+ proxy_pass http: // 127.0 . 0. 1: $ TEST_NGINX_SERVER_PORT ;
1729+ }
1730+
1731+ location / foo {
1732+ content_by_lua_block {
1733+ ngx. say (" request_uri: " , ngx. var. request_uri)
1734+ ngx. say (" uri: " , ngx. var. uri)
1735+ }
1736+ }
1737+ -- - request
1738+ GET / t
1739+ -- - error_code: 500
1740+ -- - error_log eval
1741+ qr{\[error\] \d+ # \d+: \*\d+ lua entry thread aborted: runtime error: rewrite_by_lua\(nginx.conf:\d+\):\d+: unsafe byte "0x0d" in uri "/foo\\x0D\\x0Abar" \(maybe you want to set the 'binary' argument\?\)}
1742+
1743+
1744+
1745+ === TEST 66 : set_uri binary option with safe uri
1746+ explict specify binary option to false
1747+ -- - config
1748+ location / t {
1749+ rewrite_by_lua_block {
1750+ local new_uri = " /foo bar"
1751+ ngx. req. set_uri(new_uri, false, true)
1752+ }
1753+
1754+ proxy_pass http: // 127.0 . 0. 1: $ TEST_NGINX_SERVER_PORT ;
1755+ }
1756+
1757+ location / foo {
1758+ content_by_lua_block {
1759+ ngx. say (" request_uri: " , ngx. var. request_uri)
1760+ ngx. say (" uri: " , ngx. var. uri)
1761+ }
1762+ }
1763+ -- - request
1764+ GET / t
1765+ -- - response_body
1766+ request_uri: / foo% 20bar
1767+ uri: / foo bar
1768+ -- - no_error_log
1769+ [error]
0 commit comments