Skip to content

Commit 8c97e38

Browse files
avargitster
authored andcommitted
tests: fix version-specific portability issue in Perl JSON
The test guarded by PERLJSON added in 7545941 ("json_writer: new routines to create JSON data", 2018-07-13) assumed that a JSON boolean value like "true" or "false" would be represented as "1" or "0" in Perl. This behavior can't be relied upon, e.g. with JSON.pm 2.50 and JSON::PP. A JSON::PP::Boolean object will be represented as "true" or "false". To work around this let's check if we have any refs left after we check for hashes and arrays, assume those are JSON objects, and coerce them to a known boolean value. The behavior of this test still looks odd to me. Why implement our own ad-hoc encoder just for some one-off test, as opposed to say Perl's own Data::Dumper with Sortkeys et al? But with this change it works, so let's leave it be. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3c4c88 commit 8c97e38

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

t/t0019/parse_json.perl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ sub dump_item {
3434
} elsif (ref($value) eq 'HASH') {
3535
print "$label_in hash\n";
3636
dump_hash($label_in, $value);
37+
} elsif (ref $value) {
38+
my $bool = $value ? 1 : 0;
39+
print "$label_in $bool\n";
3740
} elsif (defined $value) {
3841
print "$label_in $value\n";
3942
} else {

0 commit comments

Comments
 (0)