From 9a035a36a9c1529a4c74cda8d1e99198a73a6d13 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Sat, 1 Aug 2015 09:13:49 -0400 Subject: [PATCH] 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 dee6e022a..b19d589e1 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 431ce4dc1..73b66152d 100644 --- a/t/23json.t +++ b/t/23json.t @@ -281,7 +281,8 @@ my $json = from_json(<new( producer_args => { canonical => 1, pretty => 1, + totally_bogus_arg_to_test_arg_filtering_to_json => 1, }, data => $data, );