Permalink
Browse files

array_map_op now works.

  • Loading branch information...
1 parent d15c4c7 commit fb1155a932fdfe80bffe2d53fbdc52234bfa894d @agentzh agentzh committed Feb 12, 2010
Showing with 104 additions and 4 deletions.
  1. +3 −2 src/ngx_http_array_var_module.c
  2. +101 −2 test/t/sanity.t
@@ -279,6 +279,7 @@ ngx_http_array_map(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
"%V: expecting the \"to\" option at "
"the 3rd argument: \"%V\"",
&cmd->name, &value[3]);
+
return NGX_CONF_ERROR;
}
@@ -338,6 +339,7 @@ ngx_http_array_map_op(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (cf->args->nelts > 3 + 1) {
bad_arg = &value[4];
+
} else {
return ndk_set_var_multi_value_core(cf, &target, &value[1],
&filter);
@@ -355,7 +357,6 @@ ngx_http_array_map_op(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-
static char *
ngx_http_array_join(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
@@ -636,7 +637,7 @@ ngx_http_array_var_map_op(ngx_http_request_t *r,
}
res->data = (u_char *) new_array;
- res->len = sizeof(ngx_array_t *);
+ res->len = sizeof(ngx_array_t);
return NGX_OK;
}
View
@@ -71,7 +71,8 @@ GET /foo?names=,,,
[+++]
-=== TEST 4: array map
+
+=== TEST 5: array map
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -85,7 +86,8 @@ GET /foo?names=,,,
[hi+hi+hi+hi]
-=== TEST 4: array map
+
+=== TEST 6: array map (in-place)
--- config
location /foo {
array_split ',' $arg_names to=$names;
@@ -98,3 +100,100 @@ GET /foo?names=bob,marry,nomas
--- response_body
[bob]+[marry]+[nomas]
+
+
+=== TEST 7: array map (copy)
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map '[$array_it]' $names to=$names2;
+ array_join '+' $names;
+ array_join '+' $names2;
+ echo "$names";
+ echo "$names2";
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+bob+marry+nomas
+[bob]+[marry]+[nomas]
+
+
+
+=== TEST 8: array map (empty values)
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map '[$array_it]' $names;
+ array_join '+' $names;
+ echo "$names";
+ }
+--- request
+GET /foo?names=,marry,nomas
+--- response_body
+[]+[marry]+[nomas]
+
+
+
+=== TEST 9: non-in-place join
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_join '+' $names to=$res;
+ array_join '-' $names to=$res2;
+ echo $res;
+ echo $res2;
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+bob+marry+nomas
+bob-marry-nomas
+
+
+
+=== TEST 10: non-in-place join
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_join '+' $names to=$res;
+ array_join '-' $names to=$res2;
+ echo $res;
+ echo $res2;
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+bob+marry+nomas
+bob-marry-nomas
+
+
+
+=== TEST 11: map op
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map_op set_quote_sql_str $names;
+ array_join '+' $names to=$res;
+ echo $res;
+ }
+--- request
+GET /foo?names=bob,marry,nomas
+--- response_body
+'bob'+'marry'+'nomas'
+
+
+
+=== TEST 12: map op
+--- config
+ location /foo {
+ array_split ',' $arg_names to=$names;
+ array_map_op set_quote_sql_str $names;
+ array_join '+' $names to=$res;
+ echo $res;
+ }
+--- request
+GET /foo?names=',\
+--- response_body
+'\''+'\\'
+

0 comments on commit fb1155a

Please sign in to comment.