Skip Menu |

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

Report information
The Basics
Id: 42119
Status: resolved
Worked: 15 min
Priority: 0/
Queue: YAML-Tiny

People
Owner: jkeenan [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc: KENTNL [...] cpan.org
AdminCc:

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



Subject: write of two single quotes
Date: Sun, 04 Jan 2009 09:20:06 +1100
To: bug-YAML-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With YAML::Tiny 1.35 and debian perl 5.10.0 a program use YAML::Tiny; my $yaml = YAML::Tiny->new; $yaml->[0]->{author} = "foo ' bar ' quux"; print $yaml->write_string; prints author: 'foo '' bar ' quux' where I hoped the second ' would be doubled too like author: 'foo '' bar '' quux' I think the latter is what the spec calls for, per "Example 2.17. Quoted Scalars" under "2.3. Scalars". I noticed this on the MooseX-Types META.yml where the author has two quotes and which failed to load in YAML.pm LoadFile(). http://search.cpan.org/src/JJNAPIORK/MooseX-Types-0.08/META.yml
Just got bitten by this a bit, PAUSE sent me a message saying it couldn't parse my META.yml. Attached is a codeblock that emulates my problem and should return to working when this bug is fixed.
#!/usr/bin/perl use strict; use warnings; use version; our $VERSION = qv('0.1'); use YAML::Tiny; use Carp qw( cluck ); use Data::Dumper; my $o = YAML::Tiny->new(); my @stack = (); for ( qw( a b c d e f )){ push @stack, $_; $o->[0]->{$_ . '_whitespace'} = ' ' . join q{ ' }, @stack; } @stack = (); for ( qw( a b c d e f )){ push @stack, $_; $o->[0]->{$_.'_nowhitespace'} = '' . join q{'}, @stack; } print "Generated YAML<<'EOF';\n"; print $o->write_string; print "\nEOF\n"; use YAML::XS; eval { YAML::XS::Load( $o->write_string ); 1; } or cluck "YXS: Failed to reload>> $@ $!"; eval { my $p; $p = YAML::Tiny->read_string( $o->write_string ); print Dumper( $p ); if( $p->errstr ){ cluck "YTiny: Error ". $p->errstr; } 1; } or cluck "YTiny: Failed to reload>> $@ $!"; __END__ Generated YAML<<'EOF'; --- a_nowhitespace: a a_whitespace: ' a' b_nowhitespace: a'b b_whitespace: ' a '' b' c_nowhitespace: a'b'c c_whitespace: ' a '' b ' c' d_nowhitespace: a'b'c'd d_whitespace: ' a '' b ' c ' d' e_nowhitespace: a'b'c'd'e e_whitespace: ' a '' b ' c ' d ' e' f_nowhitespace: a'b'c'd'e'f f_whitespace: ' a '' b ' c ' d ' e ' f' EOF YXS: Failed to reload>> YAML::XS::Load Error: The problem: did not find expected key was found at document: 1, line: 7, column: 26 while parsing a block mapping at line: 2, column: 1 at tiny.pl line 30 $VAR1 = bless( [ { 'b_nowhitespace' => 'a\'b', 'a_nowhitespace' => 'a', 'e_nowhitespace' => 'a\'b\'c\'d\'e', 'a_whitespace' => ' a', 'd_whitespace' => ' a \' b \' c \' d', 'f_whitespace' => ' a \' b \' c \' d \' e \' f', 'e_whitespace' => ' a \' b \' c \' d \' e', 'b_whitespace' => ' a \' b', 'c_nowhitespace' => 'a\'b\'c', 'd_nowhitespace' => 'a\'b\'c\'d', 'c_whitespace' => ' a \' b \' c', 'f_nowhitespace' => 'a\'b\'c\'d\'e\'f' } ], 'YAML::Tiny' );
It appears to be a broken regular expression just missing the final /g. Applying the above diff works for my small test-case.
--- Tiny.pm.o 2009-05-16 02:32:15.500694315 +1200 +++ Tiny.pm 2009-05-16 02:32:44.737692186 +1200 @@ -381,7 +381,7 @@ return qq{"$str"}; } if ( length($str) == 0 or $str =~ /(?:^\W|\s)/ ) { - $str =~ s/\'/\'\'/; + $str =~ s/\'/\'\'/g; return "'$str'"; } return $str;
I can confirm this problem is solved for me in 1.38. Thanks :)
From: ckoenig [...] yahoo-inc.com
On Sat May 16 18:44:52 2009, KENTNL wrote: Show quoted text
> I can confirm this problem is solved for me in 1.38. Thanks :)
Agreed, bumping to 1.38 fixed things for me. Thank you!
On Tue Jun 09 15:52:51 2009, ckoenig wrote: Show quoted text
> On Sat May 16 18:44:52 2009, KENTNL wrote:
> > I can confirm this problem is solved for me in 1.38. Thanks :)
> > Agreed, bumping to 1.38 fixed things for me. Thank you!
Also confirmed in YAML-Tiny v1.56 with Perl 5.18.1. Closing ticket. Thank you very much. Jim Keenan