1# vi:filetype=
2
3use lib 'lib';
4use Test::Nginx::Socket;
5
6#repeat_each(3);
7
8plan tests => repeat_each() * 2 * blocks();
9
10no_long_string();
11
12run_tests();
13
14#no_diff();
15
16__DATA__
17
18=== TEST 1: set quote sql value
19--- config
20    location /foo {
21        set $foo "hello\n\r'\"\\";
22        set_quote_sql_str $foo $foo;
23        echo $foo;
24    }
25--- request
26GET /foo
27--- response_body
28'hello\n\r\'\"\\'
29
30
31
32=== TEST 2: set quote sql value (in place)
33--- config
34    location /foo {
35        set $foo "hello\n\r'\"\\";
36        set_quote_sql_str $foo;
37        echo $foo;
38    }
39--- request
40GET /foo
41--- response_body
42'hello\n\r\'\"\\'
43
44
45
46=== TEST 3: set quote empty sql value
47--- config
48    location /foo {
49        set $foo "";
50        set_quote_sql_str $foo;
51        echo $foo;
52    }
53--- request
54GET /foo
55--- response_body
56''
57
58
59
60=== TEST 4: set quote null sql value
61--- config
62    location /foo {
63        set_quote_sql_str $foo;
64        echo $foo;
65    }
66--- request
67GET /foo
68--- response_body
69''
70
71
72
73=== TEST 5: set quote null pgsql value
74--- config
75    location /foo {
76        set_quote_pgsql_str $foo;
77        echo $foo;
78    }
79--- request
80GET /foo
81--- response_body
82''
83
84
85
86=== TEST 6: set quote pgsql value
87--- config
88    location /foo {
89        set $foo "hello\n\r'\"\\";
90        set_quote_pgsql_str $foo;
91        echo $foo;
92    }
93--- request
94GET /foo
95--- response_body
96E'hello\n\r\'\"\\'
97
98
99
100=== TEST 7: set quote pgsql valid utf8 value
101--- config
102    location /foo {
103        set $foo "你好";
104        set_quote_pgsql_str $foo;
105        echo $foo;
106    }
107--- request
108GET /foo
109--- response_body
110E'你好'
111
112
113
114=== TEST 8: set quote pgsql invalid utf8 value
115--- config
116    location /foo {
117        set $foo "你好";
118        set_iconv $foo $foo from=utf-8 to=gbk;
119        set_quote_pgsql_str $foo;
120        echo $foo;
121    }
122--- request
123GET /foo
124--- response_body
125E'\\304\\343\\272\\303'
126
127
128
129=== TEST 9: \0 for mysql
130--- config
131    location /foo {
132        set_unescape_uri $foo $arg_a;
133        set_quote_sql_str $foo $foo;
134        echo $foo;
135    }
136--- request
137GET /foo?a=a%00b%00
138--- response_body
139'a\0b\0'
140
141
142
143=== TEST 10: \b for mysql
144--- config
145    location /foo {
146        set_unescape_uri $foo $arg_a;
147        set_quote_sql_str $foo $foo;
148        echo $foo;
149    }
150--- request
151GET /foo?a=a%08b%08
152--- response_body
153'a\bb\b'
154
155
156
157=== TEST 11: \t for mysql
158--- config
159    location /foo {
160        set_unescape_uri $foo $arg_a;
161        set_quote_sql_str $foo $foo;
162        echo $foo;
163    }
164--- request
165GET /foo?a=a%09b%09
166--- response_body
167'a\tb\t'
168
169
170
171=== TEST 12: \Z for mysql
172--- config
173    location /foo {
174        set_unescape_uri $foo $arg_a;
175        set_quote_sql_str $foo $foo;
176        echo $foo;
177    }
178--- request
179GET /foo?a=a%1ab%1a
180--- response_body
181'a\Zb\Z'
182
183
184
185=== TEST 13: set quote sql value
186--- config
187    location /foo {
188        set_unescape_uri $foo $arg_a;
189        set_quote_sql_str $foo $foo;
190        echo $foo;
191    }
192--- request
193GET /foo?a=$$
194--- response_body
195'\$\$'
196