Skip Menu |

This queue is for tickets about the YAML-Tiny CPAN distribution.

Report information
The Basics
Id: 41536
Status: open
Priority: 0/
Queue: YAML-Tiny

People
Owner: Nobody in particular
Requestors: paul.clifford [...] bbc.co.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Compatibility with Ruby's yaml module
Date: Mon, 08 Dec 2008 12:30:13 +0000
To: bug-YAML-Tiny [...] rt.cpan.org
From: Paul Clifford <paul.clifford [...] bbc.co.uk>
Ruby's yaml module uses "- " as the indent for list items: $ ruby -ryaml -e 'print YAML.dump({"a" => [42], "b" => [42]})' --- a: - 42 b: - 42 YAML::Tiny can't parse this because it assumes that the indent level is only determined by the number of leading spaces: $ perl -MYAML::Tiny -e 'YAML::Tiny::Load("--- \na: \n- 42\nb: \n- 42\n")' YAML::Tiny does not support the line 'b: ' at /usr/lib/perl5/vendor_perl/5.10.0/YAML/Tiny.pm line 236. On the other hand, YAML::Syck does recognise it: $ perl -MYAML::Syck -e 'Load("--- \na: \n- 42\nb: \n- 42\n")' (no output) Here's a patch to YAML-Tiny-1.34_01 which fixes the problem. There's a similar bug in the YAML library so the new test uses noyamlpm: http://rt.cpan.org/Public/Bug/Display.html?id=25945 http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this.
diff --git a/lib/YAML/Tiny.pm b/lib/YAML/Tiny.pm index df903c8..e03403f 100644 --- a/lib/YAML/Tiny.pm +++ b/lib/YAML/Tiny.pm @@ -190,8 +190,8 @@ sub _read_array { } # Check the indent level - $lines->[0] =~ /^(\s*)/; - if ( length($1) < $indent->[-1] ) { + $lines->[0] =~ /^(\s*)(-?)/; + if ( length($1) < $indent->[-1] or $2 ne '-' ) { return 1; } elsif ( length($1) > $indent->[-1] ) { die "Hash line over-indented"; diff --git a/t/02_basic.t b/t/02_basic.t index 994be4e..03675a7 100644 --- a/t/02_basic.t +++ b/t/02_basic.t @@ -10,7 +10,7 @@ BEGIN { use File::Spec::Functions ':ALL'; use t::lib::Test; -use Test::More tests(30); +use Test::More tests(31); use YAML::Tiny; @@ -129,6 +129,20 @@ END_YAML 'array_in_hash', ); +# Array inside a hash, with no leading spaces +yaml_ok( + <<'END_YAML', +--- +a: +- 42 +b: +- 42 +END_YAML + [ { a => [ 42 ], b => [ 42 ] } ], + 'array_in_hash', + noyamlpm => 1, +); + # Simple hash inside a hash with an undef yaml_ok( <<'END_YAML',
Subject: Re: [rt.cpan.org #41536] Compatibility with Ruby's yaml module
Date: Tue, 9 Dec 2008 00:45:31 +1100
To: bug-YAML-Tiny [...] rt.cpan.org
From: "Adam Kennedy" <adamkennedybackup [...] gmail.com>
Thanks for the patch. Is this only a problem at the root level, or in nested stuff as well? If so, can we add some extra tests to make sure we cover the nested cases? Adam K 2008/12/8 Paul Clifford via RT <bug-YAML-Tiny@rt.cpan.org>: Show quoted text
> Mon Dec 08 07:31:48 2008: Request 41536 was acted upon. > Transaction: Ticket created by paul.clifford@bbc.co.uk > Queue: YAML-Tiny > Subject: Compatibility with Ruby's yaml module > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: paul.clifford@bbc.co.uk > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=41536 > > > > Ruby's yaml module uses "- " as the indent for list items: > > $ ruby -ryaml -e 'print YAML.dump({"a" => [42], "b" => [42]})' > --- > a: > - 42 > b: > - 42 > > > YAML::Tiny can't parse this because it assumes that the indent level is > only determined by the number of leading spaces: > > $ perl -MYAML::Tiny -e 'YAML::Tiny::Load("--- \na: \n- 42\nb: \n- 42\n")' > YAML::Tiny does not support the line 'b: ' at > /usr/lib/perl5/vendor_perl/5.10.0/YAML/Tiny.pm line 236. > > > On the other hand, YAML::Syck does recognise it: > > $ perl -MYAML::Syck -e 'Load("--- \na: \n- 42\nb: \n- 42\n")' > (no output) > > > Here's a patch to YAML-Tiny-1.34_01 which fixes the problem. There's a > similar bug in the YAML library so the new test uses noyamlpm: > http://rt.cpan.org/Public/Bug/Display.html?id=25945 > > http://www.bbc.co.uk/ > This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. > If you have received it in error, please delete it from your system. > Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. > Please note that the BBC monitors e-mails sent or received. > Further communication will signify your consent to this. > > > > diff --git a/lib/YAML/Tiny.pm b/lib/YAML/Tiny.pm > index df903c8..e03403f 100644 > --- a/lib/YAML/Tiny.pm > +++ b/lib/YAML/Tiny.pm > @@ -190,8 +190,8 @@ sub _read_array { > } > > # Check the indent level > - $lines->[0] =~ /^(\s*)/; > - if ( length($1) < $indent->[-1] ) { > + $lines->[0] =~ /^(\s*)(-?)/; > + if ( length($1) < $indent->[-1] or $2 ne '-' ) { > return 1; > } elsif ( length($1) > $indent->[-1] ) { > die "Hash line over-indented"; > diff --git a/t/02_basic.t b/t/02_basic.t > index 994be4e..03675a7 100644 > --- a/t/02_basic.t > +++ b/t/02_basic.t > @@ -10,7 +10,7 @@ BEGIN { > > use File::Spec::Functions ':ALL'; > use t::lib::Test; > -use Test::More tests(30); > +use Test::More tests(31); > use YAML::Tiny; > > > @@ -129,6 +129,20 @@ END_YAML > 'array_in_hash', > ); > > +# Array inside a hash, with no leading spaces > +yaml_ok( > + <<'END_YAML', > +--- > +a: > +- 42 > +b: > +- 42 > +END_YAML > + [ { a => [ 42 ], b => [ 42 ] } ], > + 'array_in_hash', > + noyamlpm => 1, > +); > + > # Simple hash inside a hash with an undef > yaml_ok( > <<'END_YAML', > >
Subject: Re: [rt.cpan.org #41536] Compatibility with Ruby's yaml module
Date: Mon, 08 Dec 2008 16:19:59 +0000
To: bug-YAML-Tiny [...] rt.cpan.org
From: Paul Clifford <paul.clifford [...] bbc.co.uk>
Adam Kennedy via RT wrote: Show quoted text
> Is this only a problem at the root level, or in nested stuff as well? > > If so, can we add some extra tests to make sure we cover the nested cases?
It affects arrays at all levels. I've added a couple more tests for some nesting scenarios, and given them unique names which I forgot in the first patch. There's still a problem with arrays nested within arrays, eg: $ ruby -ryaml -e 'p YAML.dump([[10]])' "--- \n- - 10\n" $ perl -MYAML::Tiny -MData::Dumper -e 'print Dumper(YAML::Tiny::Load("--- \n- - 10\n"))' $VAR1 = [ '- 10' ]; $ perl -MYAML::Syck -MData::Dumper -e 'print Dumper(Load("--- \n- - 10\n"))' $VAR1 = [ [ '10' ] ]; However, this looks like a more complicated fix and doesn't affect any of the data I'm currently using, so I'd prefer to look at it in a different bug if that's okay? http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this.
diff --git a/lib/YAML/Tiny.pm b/lib/YAML/Tiny.pm index df903c8..e03403f 100644 --- a/lib/YAML/Tiny.pm +++ b/lib/YAML/Tiny.pm @@ -190,8 +190,8 @@ sub _read_array { } # Check the indent level - $lines->[0] =~ /^(\s*)/; - if ( length($1) < $indent->[-1] ) { + $lines->[0] =~ /^(\s*)(-?)/; + if ( length($1) < $indent->[-1] or $2 ne '-' ) { return 1; } elsif ( length($1) > $indent->[-1] ) { die "Hash line over-indented"; diff --git a/t/02_basic.t b/t/02_basic.t index 994be4e..0e5b624 100644 --- a/t/02_basic.t +++ b/t/02_basic.t @@ -10,7 +10,7 @@ BEGIN { use File::Spec::Functions ':ALL'; use t::lib::Test; -use Test::More tests(30); +use Test::More tests(33); use YAML::Tiny; @@ -129,6 +129,55 @@ END_YAML 'array_in_hash', ); +# Arrays inside a hash, with no leading space for the "-" indicator +yaml_ok( + <<'END_YAML', +--- +a: +- 42 +b: +- 84 +END_YAML + [ { a => [ 42 ], b => [ 84 ] } ], + 'no_array_indent1', + noyamlpm => 1, +); + +# Arrays inside a nested hash, with no leading space for the "-" indicator +yaml_ok( + <<'END_YAML', +--- +a: + aa: + - 42 + ab: + - + - "test" +b: 10 +END_YAML + [ { a => { aa => [ 42 ], ab => [ undef, "test" ] }, b => 10 } ], + 'no_array_indent2', + noyamlpm => 1, +); + +# Nested arrays within hashes, with no leading space for the "-" indicator +yaml_ok( + <<'END_YAML', +--- +a: +- aa: + - 42 + ab: + - + - "test" +b: +- 10 +END_YAML + [ { a => [ { aa => [ 42 ], ab => [ undef, "test" ] } ], b => [ 10 ] } ], + 'no_array_indent3', + noyamlpm => 1, +); + # Simple hash inside a hash with an undef yaml_ok( <<'END_YAML',
Subject: Re: [rt.cpan.org #41536] Compatibility with Ruby's yaml module
Date: Tue, 9 Dec 2008 10:38:29 +1100
To: bug-YAML-Tiny [...] rt.cpan.org
From: "Adam Kennedy" <adamkennedybackup [...] gmail.com>
OK, we'll treat it as separate. Adam K 2008/12/9 Paul Clifford via RT <bug-YAML-Tiny@rt.cpan.org>: Show quoted text
> Queue: YAML-Tiny > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=41536 > > > Adam Kennedy via RT wrote:
>> Is this only a problem at the root level, or in nested stuff as well? >> >> If so, can we add some extra tests to make sure we cover the nested cases?
> > It affects arrays at all levels. I've added a couple more tests for > some nesting scenarios, and given them unique names which I forgot in > the first patch. > > There's still a problem with arrays nested within arrays, eg: > > $ ruby -ryaml -e 'p YAML.dump([[10]])' > "--- \n- - 10\n" > > $ perl -MYAML::Tiny -MData::Dumper -e 'print > Dumper(YAML::Tiny::Load("--- \n- - 10\n"))' > $VAR1 = [ > '- 10' > ]; > > $ perl -MYAML::Syck -MData::Dumper -e 'print Dumper(Load("--- \n- - 10\n"))' > $VAR1 = [ > [ > '10' > ] > ]; > > However, this looks like a more complicated fix and doesn't affect any > of the data I'm currently using, so I'd prefer to look at it in a > different bug if that's okay? > > http://www.bbc.co.uk/ > This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. > If you have received it in error, please delete it from your system. > Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. > Please note that the BBC monitors e-mails sent or received. > Further communication will signify your consent to this. > > > > diff --git a/lib/YAML/Tiny.pm b/lib/YAML/Tiny.pm > index df903c8..e03403f 100644 > --- a/lib/YAML/Tiny.pm > +++ b/lib/YAML/Tiny.pm > @@ -190,8 +190,8 @@ sub _read_array { > } > > # Check the indent level > - $lines->[0] =~ /^(\s*)/; > - if ( length($1) < $indent->[-1] ) { > + $lines->[0] =~ /^(\s*)(-?)/; > + if ( length($1) < $indent->[-1] or $2 ne '-' ) { > return 1; > } elsif ( length($1) > $indent->[-1] ) { > die "Hash line over-indented"; > diff --git a/t/02_basic.t b/t/02_basic.t > index 994be4e..0e5b624 100644 > --- a/t/02_basic.t > +++ b/t/02_basic.t > @@ -10,7 +10,7 @@ BEGIN { > > use File::Spec::Functions ':ALL'; > use t::lib::Test; > -use Test::More tests(30); > +use Test::More tests(33); > use YAML::Tiny; > > > @@ -129,6 +129,55 @@ END_YAML > 'array_in_hash', > ); > > +# Arrays inside a hash, with no leading space for the "-" indicator > +yaml_ok( > + <<'END_YAML', > +--- > +a: > +- 42 > +b: > +- 84 > +END_YAML > + [ { a => [ 42 ], b => [ 84 ] } ], > + 'no_array_indent1', > + noyamlpm => 1, > +); > + > +# Arrays inside a nested hash, with no leading space for the "-" indicator > +yaml_ok( > + <<'END_YAML', > +--- > +a: > + aa: > + - 42 > + ab: > + - > + - "test" > +b: 10 > +END_YAML > + [ { a => { aa => [ 42 ], ab => [ undef, "test" ] }, b => 10 } ], > + 'no_array_indent2', > + noyamlpm => 1, > +); > + > +# Nested arrays within hashes, with no leading space for the "-" indicator > +yaml_ok( > + <<'END_YAML', > +--- > +a: > +- aa: > + - 42 > + ab: > + - > + - "test" > +b: > +- 10 > +END_YAML > + [ { a => [ { aa => [ 42 ], ab => [ undef, "test" ] } ], b => [ 10 ] } ], > + 'no_array_indent3', > + noyamlpm => 1, > +); > + > # Simple hash inside a hash with an undef > yaml_ok( > <<'END_YAML', > >