1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(2);
plan tests => repeat_each() * 2 * blocks();
#$Test::Nginx::LWP::LogLevel = 'debug';
run_tests();
__DATA__
=== TEST 1: sanity
--- config
location /main {
echo_foreach_split '&' $query_string;
echo_location_async $echo_it;
echo '/* end */';
echo_end;
}
location /sub/1.css {
echo "body { font-size: 12pt; }";
}
location /sub/2.css {
echo "table { color: 'red'; }";
}
--- request
GET /main?/sub/1.css&/sub/2.css
--- response_body
body { font-size: 12pt; }
/* end */
table { color: 'red'; }
/* end */
=== TEST 2: split in a url argument (echo_location_async)
--- config
location /main_async {
echo_foreach_split ',' $arg_cssfiles;
echo_location_async $echo_it;
echo_end;
}
location /foo.css {
echo foo;
}
location /bar.css {
echo bar;
}
location /baz.css {
echo baz;
}
--- request
GET /main_async?cssfiles=/foo.css,/bar.css,/baz.css
--- response_body
foo
bar
baz
=== TEST 3: split in a url argument (echo_location)
--- config
location /main_sync {
echo_foreach_split ',' $arg_cssfiles;
echo_location $echo_it;
echo_end;
}
location /foo.css {
echo foo;
}
location /bar.css {
echo bar;
}
location /baz.css {
echo baz;
}
--- request
GET /main_sync?cssfiles=/foo.css,/bar.css,/baz.css
--- response_body
foo
bar
baz
--- SKIP
=== TEST 4: empty loop
--- config
location /main {
echo "start";
echo_foreach_split ',' $arg_cssfiles;
echo_end;
echo "end";
}
--- request
GET /main?cssfiles=/foo.css,/bar.css,/baz.css
--- response_body
start
end
=== TEST 5: trailing delimiter
--- config
location /main_t {
echo_foreach_split ',' $arg_cssfiles;
echo_location_async $echo_it;
echo_end;
}
location /foo.css {
echo foo;
}
--- request
GET /main_t?cssfiles=/foo.css,
--- response_body
foo
=== TEST 6: multi-char delimiter
--- config
location /main_sleep {
echo_foreach_split '-a-' $arg_list;
echo $echo_it;
echo_end;
}
--- request
GET /main_sleep?list=foo-a-bar-a-baz
--- error_code: 500
--- response_body_like: 500 Internal Server Error
=== TEST 7: multi-char delimiter (the right way)
--- config
location /main_sleep {
echo_foreach_split -- '-a-' $arg_list;
echo $echo_it;
echo_end;
}
--- request
GET /main_sleep?list=foo-a-bar-a-baz
--- response_body
foo
bar
baz
=== TEST 8: loop with sleep
--- config
location /main_sleep {
echo_foreach_split '-' $arg_list;
echo_sleep 0.001;
echo $echo_it;
echo_end;
}
--- request
GET /main_sleep?list=foo-a-bar-A-baz
--- response_body
foo
a
bar
A
baz
=== TEST 9: empty
--- config
location /merge {
default_type 'text/javascript';
echo_foreach_split '&' $query_string;
echo "/* JS File $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
--- request
GET /merge
--- response_body
=== TEST 10: single &
--- config
location /merge {
default_type 'text/javascript';
echo_foreach_split '&' $query_string;
echo "/* JS File $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
--- request
GET /merge?&
--- response_body
=== TEST 11: pure &'s
--- config
location /merge {
default_type 'text/javascript';
echo_foreach_split '&' $query_string;
echo "/* JS File $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
--- request
GET /merge?&&&
--- response_body
=== TEST 12: pure & and spaces
TODO: needs to uri_decode $echo_it...
--- config
location /merge {
default_type 'text/javascript';
echo_foreach_split '&' $query_string;
echo "/* JS File $echo_it */";
echo_location_async $echo_it;
echo;
echo_end;
}
--- request
GET /merge?&%20&%20&
--- response_body
--- SKIP
=== TEST 13: multiple foreach_split
--- config
location /multi {
echo_foreach_split '&' $query_string;
echo [$echo_it];
echo_end;
echo '...';
echo_foreach_split '-' $query_string;
echo [$echo_it];
echo_end;
}
--- request
GET /multi?a-b&c-d
--- response_body
[a-b]
[c-d]
...
[a]
[b&c]
[d]
=== TEST 14: github issue #2: setting a variable from $echo_it results to crashing
--- config
location = /getFile {
set $filelist "a,b,c";
echo_foreach_split ',' $filelist;
set $file $echo_it;
echo_subrequest GET '/getFile2' -q 'sha256=$file';
echo_end;
}
location = /getFile2 {
echo "sha256: $arg_sha256";
}
--- request
GET /getFile
--- response_body
sha256:
sha256:
sha256:
|