Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a bug in compact JSON mode: the column name in the resultset mi…

…ght not be escaped for JSOn encoding.
  • Loading branch information...
commit 56bb63c35050f79f539c012eb6d64389825af7f6 1 parent 27c4bb6
@agentzh agentzh authored
View
1  .gitignore
@@ -68,3 +68,4 @@ t/servroot/
all
build10
buildroot/
+*.html
View
9 src/ngx_http_rds_json_output.c
@@ -257,13 +257,8 @@ ngx_http_rds_json_output_cols(ngx_http_request_t *r,
*last++ = '"';
- if (key_escape == 0) {
- last = ngx_copy(last, col->name.data, col->name.len);
-
- } else {
- last = (u_char *) ngx_http_rds_json_escape_json_str(last,
- col->name.data, col->name.len);
- }
+ last = (u_char *) ngx_http_rds_json_escape_json_str(last,
+ col->name.data, col->name.len);
*last++ = '"';
View
51 t/000_init.t
@@ -77,3 +77,54 @@ GET /init
GET /init
--- error_code: 200
--- timeout: 10
+
+
+
+=== TEST 5: birds - drop table
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "DROP TABLE IF EXISTS birds";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
+
+
+=== TEST 6: birds - create table
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "CREATE TABLE birds (`\"name\"` text, height real)";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
+
+
+=== TEST 7: birds - insert values
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "
+INSERT INTO birds (`\"name\"`, height)
+VALUES
+ ('hello \"tom', 3.14),
+ ('hi,ya', -3),
+ ('hey\\ndad', 7),
+ ('\\rkay', 0.005),
+ ('ab;c', 0.005),
+ ('foo\\tbar', 21);";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
View
58 t/escape.t
@@ -0,0 +1,58 @@
+# vi:filetype=
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+
+plan tests => repeat_each() * 2 * blocks();
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream backend {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test;
+ }
+_EOC_
+
+no_long_string();
+no_diff();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: escaping table names (normal mode)
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_query "
+ select `\"name\"`, height from birds order by height;
+ ";
+ drizzle_pass backend;
+ rds_json on;
+ }
+--- request
+GET /mysql
+--- response_body chomp
+[{"\"name\"":"hi,ya","height":-3},{"\"name\"":"\rkay","height":0.005},{"\"name\"":"ab;c","height":0.005},{"\"name\"":"hello \"tom","height":3.14},{"\"name\"":"hey\ndad","height":7},{"\"name\"":"foo\tbar","height":21}]
+
+
+
+=== TEST 2: escaping table names (compact mode)
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_query "
+ select `\"name\"`, height from birds order by height;
+ ";
+ drizzle_pass backend;
+ rds_json on;
+ rds_json_format compact;
+ }
+--- request
+GET /mysql
+--- response_body chomp
+[["\"name\"","height"],["hi,ya",-3],["\rkay",0.005],["ab;c",0.005],["hello \"tom",3.14],["hey\ndad",7],["foo\tbar",21]]
+
View
4 t/form.t
@@ -16,10 +16,10 @@ our $http_config = <<'_EOC_';
}
_EOC_
-run_tests();
-
no_diff();
+run_tests();
+
__DATA__
=== TEST 1: sanity
Please sign in to comment.
Something went wrong with that request. Please try again.