Permalink
Browse files

clears $array_it after calling array_map and fixed a bug in array_spl…

…it with empty seperator.
  • Loading branch information...
1 parent fb1155a commit 1ea5a69d24735add570974ee31055932de232e0f @agentzh agentzh committed May 23, 2010
Showing with 118 additions and 12 deletions.
  1. +0 −1 README
  2. +22 −0 src/ngx_http_array_var_module.c
  3. +96 −11 test/t/sanity.t
View
1 README
@@ -6,7 +6,6 @@ Name
installation instructions.
Status
- **NOT WORKING YET!!!**
This module is still under development, just
as Marcus Clyne's NDK.
View
22 src/ngx_http_array_var_module.c
@@ -453,6 +453,24 @@ ngx_http_array_var_split(ngx_http_request_t *r,
pos = str->data;
end = str->data + str->len;
+ if (sep->len == 0) {
+ /* split each char into an array elem */
+
+ while (pos != end) {
+ s = ngx_array_push(array);
+ if (s == NULL) {
+ return NGX_ERROR;
+ }
+
+ s->data = pos;
+ s->len = 1;
+
+ pos++;
+ }
+
+ goto done;
+ }
+
while ((last = ngx_http_array_var_strlstrn(pos, end, sep->data,
sep->len - 1)))
{
@@ -484,6 +502,7 @@ ngx_http_array_var_split(ngx_http_request_t *r,
dd("split: array size: %d", array->nelts);
dd("split array ptr: %p", array);
+done:
res->data = (u_char *) array;
res->len = sizeof(ngx_array_t);
@@ -561,6 +580,9 @@ ngx_http_array_var_map(ngx_http_request_t *r,
dd("array var map: new item: %.*s", new_value->len, new_value->data);
}
+ array_it->not_found = 1;
+ array_it->valid = 0;
+
res->data = (u_char *) new_array;
res->len = sizeof(ngx_array_t);
View
107 test/t/sanity.t
@@ -30,7 +30,49 @@ Bob+Marry+John
-=== TEST 2: array split/join (single item)
+=== TEST 2: array split (empty split sep)
+--- config
+ location /foo {
+ array_split '' $arg_names to=$names;
+ array_join '+' $names;
+ echo $names;
+ }
+--- request
+GET /foo?names=Bob
+--- response_body
+B+o+b
+
+
+
+=== TEST 3: array split (empty split/join sep)
+--- config
+ location /foo {
+ array_split '' $arg_names to=$names;
+ array_join '' $names;
+ echo [$names];
+ }
+--- request
+GET /foo?names=Bob
+--- response_body
+[Bob]
+
+
+
+=== TEST 4: array split (empty split + empty input)
+--- config
+ location /foo {
+ array_split '' $arg_names to=$names;
+ array_join '+' $names;
+ echo [$names];
+ }
+--- request
+GET /foo?
+--- response_body
+[]
+
+
+
+=== TEST 5: array split/join (single item)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -44,7 +86,7 @@ nomas
-=== TEST 3: array split/join (empty array)
+=== TEST 6: array split/join (empty array)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -58,7 +100,21 @@ GET /foo?
-=== TEST 4: array split/join (list of empty values)
+=== TEST 7: array split/join (multi-char sep)
+--- config
+ location /foo {
+ array_split '->' $arg_names to=$names;
+ array_join '(+)' $names;
+ echo "$names";
+ }
+--- request
+GET /foo?names=a->b->c
+--- response_body
+a(+)b(+)c
+
+
+
+=== TEST 8: array split/join (list of empty values)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -72,7 +128,7 @@ GET /foo?names=,,,
-=== TEST 5: array map
+=== TEST 9: array map
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -87,7 +143,7 @@ GET /foo?names=,,,
-=== TEST 6: array map (in-place)
+=== TEST 10: array map (in-place)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -102,7 +158,7 @@ GET /foo?names=bob,marry,nomas
-=== TEST 7: array map (copy)
+=== TEST 11: array map (copy)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -120,7 +176,7 @@ bob+marry+nomas
-=== TEST 8: array map (empty values)
+=== TEST 12: array map (empty values)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -135,7 +191,7 @@ GET /foo?names=,marry,nomas
-=== TEST 9: non-in-place join
+=== TEST 13: non-in-place join
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -152,7 +208,7 @@ bob-marry-nomas
-=== TEST 10: non-in-place join
+=== TEST 14: non-in-place join
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -169,7 +225,7 @@ bob-marry-nomas
-=== TEST 11: map op
+=== TEST 15: map op (in-place)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -184,7 +240,22 @@ GET /foo?names=bob,marry,nomas
-=== TEST 12: map op
+=== TEST 16: map op (copy)
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map_op set_quote_sql_str $names to=$list;
+ array_join '+' $list to=$res;
+ echo $res;
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+'bob'+'marry'+'nomas'
+
+
+
+=== TEST 17: map op (quote special chars)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -197,3 +268,17 @@ GET /foo?names=',\
--- response_body
'\''+'\\'
+
+
+=== TEST 18: $array_it gets cleared after array map
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map '[$array_it]' $names;
+ echo "[$array_it]";
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+[]
+

0 comments on commit 1ea5a69

Please sign in to comment.