Skip to content

Commit c6ffcfb

Browse files
zhuizhuhaomengagentzh
authored andcommitted
1 parent 785fb57 commit c6ffcfb

File tree

3 files changed

+102
-13
lines changed

3 files changed

+102
-13
lines changed

src/ngx_http_lua_uri.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ ngx_http_lua_ngx_req_set_uri(lua_State *L)
5555
return luaL_error(L, "attempt to use zero-length uri");
5656
}
5757

58-
if (ngx_http_lua_check_unsafe_string(r, p, len, "uri") != NGX_OK) {
59-
return luaL_error(L, "attempt to set unsafe uri");
60-
}
61-
6258
if (n == 2) {
6359

6460
luaL_checktype(L, 2, LUA_TBOOLEAN);

t/030-uri-args.t

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ log_level('warn');
99
repeat_each(2);
1010
#repeat_each(1);
1111

12-
plan tests => repeat_each() * (blocks() * 2 + 24);
12+
plan tests => repeat_each() * (blocks() * 2 + 22);
1313

1414
no_root_location();
1515

@@ -1568,10 +1568,9 @@ args: foo=%2C%24%40%7C%60&bar=-_.!~*'()
15681568
}
15691569
--- request
15701570
GET /t
1571-
--- error_code: 500
1572-
--- error_log
1573-
unsafe byte "0x9" in uri "/foo\x09bar"
1574-
attempt to set unsafe uri
1571+
--- error_code: 200
1572+
--- response_body eval
1573+
qr#/foo\tbar#
15751574

15761575

15771576

@@ -1586,10 +1585,9 @@ attempt to set unsafe uri
15861585
}
15871586
--- request
15881587
GET /t
1589-
--- error_code: 500
1590-
--- error_log
1591-
unsafe byte "0x0" in uri "\x00foo"
1592-
attempt to set unsafe uri
1588+
--- error_code: 200
1589+
--- response_body eval
1590+
qr/\0foo/
15931591

15941592

15951593

t/162-static-module-location.t

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use Test::Nginx::Socket::Lua;
2+
3+
repeat_each(2);
4+
5+
plan tests => repeat_each() * (blocks() * 3);
6+
7+
our $HtmlDir = html_dir;
8+
9+
no_long_string();
10+
run_tests();
11+
12+
__DATA__
13+
14+
=== TEST 1: decoded url contains '\0' and '\r\n'
15+
--- config
16+
server_tokens off;
17+
location = /t {
18+
rewrite_by_lua_block {
19+
ngx.req.read_body();
20+
local args, _ = ngx.req.get_post_args();
21+
ngx.req.set_uri(args["url"], true);
22+
}
23+
}
24+
--- request
25+
POST /t
26+
url=%00%0a%0dset-cookie:1234567
27+
--- error_code: 301
28+
--- response_headers
29+
Location: %00%0A%0Dset-cookie:1234567/
30+
--- response_body_like
31+
.*301 Moved Permanently.*
32+
33+
34+
35+
=== TEST 2: uri contain chinese characters
36+
--- config
37+
server_tokens off;
38+
--- user_files
39+
>>> t/中文/foo.txt
40+
Hello, world
41+
--- request
42+
GET /t/中文
43+
--- error_code: 301
44+
--- response_headers
45+
Location: http://localhost:1984/t/%E4%B8%AD%E6%96%87/
46+
--- response_body_like
47+
.*301 Moved Permanently.*
48+
49+
50+
51+
=== TEST 3: uri contain chinese characters with args
52+
--- config
53+
server_tokens off;
54+
--- user_files
55+
>>> t/中文/foo.txt
56+
Hello, world
57+
--- request
58+
GET /t/中文?q=name
59+
--- error_code: 301
60+
--- response_headers
61+
Location: http://localhost:1984/t/%E4%B8%AD%E6%96%87/?q=name
62+
--- response_body_like
63+
.*301 Moved Permanently.*
64+
65+
66+
67+
=== TEST 4: uri already encoded
68+
--- config
69+
server_tokens off;
70+
--- user_files
71+
>>> t/中文/foo.txt
72+
Hello, world
73+
--- request
74+
GET /t/%E4%B8%AD%E6%96%87
75+
--- error_code: 301
76+
--- response_headers
77+
Location: http://localhost:1984/t/%E4%B8%AD%E6%96%87/
78+
--- response_body_like
79+
.*301 Moved Permanently.*
80+
81+
82+
83+
=== TEST 5: uri already encoded with args
84+
--- config
85+
server_tokens off;
86+
--- user_files
87+
>>> t/中文/foo.txt
88+
Hello, world
89+
--- request
90+
GET /t/%E4%B8%AD%E6%96%87?q=name
91+
--- error_code: 301
92+
--- response_headers
93+
Location: http://localhost:1984/t/%E4%B8%AD%E6%96%87/?q=name
94+
--- response_body_like
95+
.*301 Moved Permanently.*

0 commit comments

Comments
 (0)