From b18e61c57ca2bf1b378c4e900996f03d0f8c7da3 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Sat, 1 Aug 2015 09:13:49 -0400 Subject: [PATCH 1/2] don't pass non-JSON specific producer_args to to_json The producer_args passed by sqlt contains a number of keys which are not specific to JSON. These were passed unfiltered to to_json(). JSON (at least as of v2.90) will throw an error if it is passed an unknown option (it uses the option key as a method name, which leads to confusing error messages). It's not straightforward to automatically determine the args supported by the JSON module, so this simply whitelist the 'pretty', 'indent', and 'canonical' options. --- lib/SQL/Translator/Producer/JSON.pm | 4 +++- t/23json.t | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/SQL/Translator/Producer/JSON.pm b/lib/SQL/Translator/Producer/JSON.pm index 0095316d3..27da56121 100644 --- a/lib/SQL/Translator/Producer/JSON.pm +++ b/lib/SQL/Translator/Producer/JSON.pm @@ -61,7 +61,9 @@ sub produce { }, { allow_blessed => 1, allow_unknown => 1, - %{$translator->producer_args}, + ( map { $_ => $translator->producer_args->{$_} } + grep { defined $translator->producer_args->{$_} } + qw[ pretty indent canonical ] ), }); } diff --git a/t/23json.t b/t/23json.t index 0b063e2cc..dd78640e9 100644 --- a/t/23json.t +++ b/t/23json.t @@ -276,7 +276,8 @@ my $json = to_json(from_json(< 1, pretty => 1 }); "parser_type" : "SQL::Translator::Parser::SQLite", "producer_args" : { "canonical" : 1, - "pretty" : 1 + "pretty" : 1, + "totally_bogus_arg_to_test_arg_filtering_to_json" : 1 }, "producer_type" : "SQL::Translator::Producer::JSON", "show_warnings" : 0, @@ -296,6 +297,7 @@ my $tr = SQL::Translator->new( producer_args => { canonical => 1, pretty => 1, + totally_bogus_arg_to_test_arg_filtering_to_json => 1, }, data => $data, ); From 97fd40c6abbc7b56bac86712fb3e2302f3c33e7f Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Fri, 4 Sep 2015 15:57:55 -0400 Subject: [PATCH 2/2] remove introduced tabs --- lib/SQL/Translator/Producer/JSON.pm | 4 ++-- t/23json.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/SQL/Translator/Producer/JSON.pm b/lib/SQL/Translator/Producer/JSON.pm index 27da56121..bde0cca33 100644 --- a/lib/SQL/Translator/Producer/JSON.pm +++ b/lib/SQL/Translator/Producer/JSON.pm @@ -62,8 +62,8 @@ sub produce { allow_blessed => 1, allow_unknown => 1, ( map { $_ => $translator->producer_args->{$_} } - grep { defined $translator->producer_args->{$_} } - qw[ pretty indent canonical ] ), + grep { defined $translator->producer_args->{$_} } + qw[ pretty indent canonical ] ), }); } diff --git a/t/23json.t b/t/23json.t index dd78640e9..bbaf4e42c 100644 --- a/t/23json.t +++ b/t/23json.t @@ -277,7 +277,7 @@ my $json = to_json(from_json(< 1, pretty => 1 }); "producer_args" : { "canonical" : 1, "pretty" : 1, - "totally_bogus_arg_to_test_arg_filtering_to_json" : 1 + "totally_bogus_arg_to_test_arg_filtering_to_json" : 1 }, "producer_type" : "SQL::Translator::Producer::JSON", "show_warnings" : 0, @@ -297,7 +297,7 @@ my $tr = SQL::Translator->new( producer_args => { canonical => 1, pretty => 1, - totally_bogus_arg_to_test_arg_filtering_to_json => 1, + totally_bogus_arg_to_test_arg_filtering_to_json => 1, }, data => $data, );