Re: [Module::Build] broken META.yml file
Status: Beta
Brought to you by:
kwilliams
From: Ken W. <ke...@ma...> - 2006-05-12 21:25:32
|
Hi Stephen, The patch looks good except that it got mangled a little in the email message. I've applied it and all tests pass for me. Thanks! -Ken On May 11, 2006, at 11:50 PM, Stephen Adkins wrote: > Hi, > > I wrote Module::Build::YAML. > I offer these patches. > > Both of the previously mentioned broken YAML files were a > result of embedded newlines. I opted to tackle newlines and > all of the other special characters which I could find which > YAML considers special. > > I think this version will be quite an improvement in terms of > robustness in the presence of "odd" characters in the scalar > values. I patched > > lib/Module/Build/YAML.pm > t/mbyaml.t > > The "svn diff" is below. I also attach a tar.gz of the two full > files in case > I did the patch wrong. > > Stephen > > spadkins@pompeii:/usr/rubicon/spadkins/src/app/Module-Build> svn diff > Index: t/mbyaml.t > =================================================================== > --- t/mbyaml.t (revision 6288) > +++ t/mbyaml.t (working copy) > @@ -9,9 +9,12 @@ > $dir = "t" if (-d "t"); > > { > - use_ok("Module::Build::YAML"); > - my ($expected, $got, $var); > - $var = { > + use_ok("Module::Build::YAML"); > + my ($expected, $got, $var); > + ########################################################## > + # Test a typical-looking Module::Build structure (alphabetized) > + ########################################################## > + $var = { > 'resources' => { > 'license' => > 'http://opensource.org/licenses/artistic-license.php' > }, > @@ -43,11 +46,11 @@ > }, > 'abstract' => 'A framework for building dynamic widgets or > full applications in Javascript' > }; > - $expected = <<EOF; > + $expected = <<'EOF'; > --- > abstract: A framework for building dynamic widgets or full > applications in Javascript > author: > - - '"Stephen Adkins" <spadkins\@gmail.com>' > + - '"Stephen Adkins" <spa...@gm...>' > build_requires: > App::Build: 0 > File::Spec: 0 > @@ -72,12 +75,15 @@ > $got = &Module::Build::YAML::Dump($var); > is($got, $expected, "Dump(): single deep hash"); > > - $expected = <<EOF; > + ########################################################## > + # Test a typical-looking Module::Build structure (ordered) > + ########################################################## > + $expected = <<'EOF'; > --- > name: js-app > version: 0.13 > author: > - - '"Stephen Adkins" <spadkins\@gmail.com>' > + - '"Stephen Adkins" <spa...@gm...>' > abstract: A framework for building dynamic widgets or full > applications in Javascript > license: lgpl > resources: > @@ -102,13 +108,16 @@ > $got = &Module::Build::YAML::Dump($var); > is($got, $expected, "Dump(): single deep hash, ordered"); > > + ########################################################## > + # Test that an array turns into multiple documents > + ########################################################## > $var = [ > "e", > 2.71828, > [ "pi", "is", 3.1416 ], > { fun => "under_sun", 6 => undef, "more", undef }, > ]; > - $expected = <<EOF; > + $expected = <<'EOF'; > --- > e > --- > @@ -118,14 +127,17 @@ > - is > - 3.1416 > --- > -6: "" > +6: ~ > fun: under_sun > -more: "" > +more: ~ > EOF > $got = &Module::Build::YAML::Dump(@$var); > is($got, $expected, "Dump(): multiple, various"); > > - $expected = <<EOF; > + ########################################################## > + # Test that a single array ref turns into one document > + ########################################################## > + $expected = <<'EOF'; > --- > - e > - 2.71828 > @@ -134,16 +146,115 @@ > - is > - 3.1416 > - > - 6: "" > + 6: ~ > fun: under_sun > - more: "" > + more: ~ > EOF > $got = &Module::Build::YAML::Dump($var); > is($got, $expected, "Dump(): single array of various"); > > + ########################################################## > + # Test Object-Oriented Flavor of the API > + ########################################################## > my $y = Module::Build::YAML->new(); > $got = $y->Dump($var); > is($got, $expected, "Dump(): single array of various (OO)"); > + > + ########################################################## > + # Test Quoting Conditions (newlines, quotes, tildas, undefs) > + ########################################################## > + $var = { > + 'foo01' => '`~!@#$%^&*()_+-={}|[]\\;\':",./?<> > +<nl>', > + 'foo02' => '~!@#$%^&*()_+-={}|[]\\;:,./<>?', > + 'foo03' => undef, > + 'foo04' => '~', > + }; > + $expected = <<'EOF'; > +--- > +foo01: "`~!@#$%^&*()_+-={}|[]\;':\",./?<>\n<nl>" > +foo02: "~!@#$%^&*()_+-={}|[]\;:,./<>?" > +foo03: ~ > +foo04: "~" > +EOF > + $got = &Module::Build::YAML::Dump($var); > + is($got, $expected, "Dump(): tricky embedded characters"); > + > + $var = { > + 'foo10' => undef, > + 'foo40' => '!', > + 'foo41' => '@', > + 'foo42' => '#', > + 'foo43' => '$', > + 'foo44' => '%', > + 'foo45' => '^', > + 'foo47' => '&', > + 'foo48' => '*', > + 'foo49' => '(', > + 'foo50' => ')', > + 'foo51' => '_', > + 'foo52' => '+', > + 'foo53' => '-', > + 'foo54' => '=', > + 'foo55' => '{', > + 'foo56' => '}', > + 'foo57' => '|', > + 'foo58' => '[', > + 'foo59' => ']', > + 'foo60' => '\\', > + 'foo61' => ';', > + 'foo62' => ':', > + 'foo63' => ',', > + 'foo64' => '.', > + 'foo65' => '/', > + 'foo66' => '<', > + 'foo67' => '>', > + 'foo68' => '?', > + 'foo69' => '\'', > + 'foo70' => '"', > + 'foo71' => '`', > + 'foo72' => ' > +', > + }; > + $expected = <<'EOF'; > +--- > +foo10: ~ > +foo40: "!" > +foo41: '@' > +foo42: "#" > +foo43: $ > +foo44: % > +foo45: "^" > +foo47: "&" > +foo48: "*" > +foo49: "(" > +foo50: ")" > +foo51: _ > +foo52: + > +foo53: - > +foo54: = > +foo55: "{" > +foo56: "}" > +foo57: "|" > +foo58: "[" > +foo59: "]" > +foo60: \ > +foo61: ; > +foo62: : > +foo63: , > +foo64: . > +foo65: / > +foo66: '<' > +foo67: '>' > +foo68: "?" > +foo69: "'" > +foo70: '"' > +foo71: "`" > +foo72: "\n" > +EOF > + $got = &Module::Build::YAML::Dump($var); > + is($got, $expected, "Dump(): tricky embedded characters > (singles)"); > + > } > > > Index: lib/Module/Build/YAML.pm > =================================================================== > --- lib/Module/Build/YAML.pm (revision 6288) > +++ lib/Module/Build/YAML.pm (working copy) > @@ -102,26 +102,31 @@ > } > > sub _yaml_value { > - # XXX doesn't handle embedded newlines > my ($value) = @_; > - # undefs and empty strings will become empty strings > - if (! defined $value || $value eq "") { > + # undefs become ~ > + if (! defined $value) { > + return("~"); > + } > + # empty strings will become empty strings > + elsif (! defined $value || $value eq "") { > return('""'); > } > + # quote and escape strings with special values > + elsif ($value =~ /["'`~\n!\@\#^\&\*\(\)\{\}\[\]\|<>\?]/) { > + if ($value !~ /['`~\n!\#^\&\*\(\)\{\}\[\]\|\?]/) { # nothing but > " or @ or < or > (email addresses) > + return("'" . $value . "'"); > + } > + else { > + $value =~ s/\n/\\n/g; # handle embedded newlines > + $value =~ s/"/\\"/g; # handle embedded quotes > + return('"' . $value . '"'); > + } > + } > # allow simple scalars (without embedded quote chars) to be unquoted > - elsif ($value !~ /["'\\]/) { > + # (includes $%_+=-\;:,./) > + else { > return($value); > } > - # strings without double-quotes get double-quoted > - elsif ($value !~ /\"/) { > - $value =~ s{\\}{\\\\}g; > - return qq{"$value"}; > - } > - # other strings get single-quoted > - else { > - $value =~ s{([\\'])}{\\$1}g; > - return qq{'$value'}; > - } > } > > 1; > ================================================= > > On 5/11/06, Johan Vromans <jvr...@sq...> wrote: >> and...@fr... (Andreas J. Koenig) writes: >> >> >>>>>> On Wed, 10 May 2006 08:40:33 +0200, >> and...@fr... (Andreas J. Koenig) said: >> > >> > > This seems to be a bug in Module::Build that is still there >> in 0.28. >> > >> > Another case where Module::Build without YAML fails is PHILCROW/ >> Gantry-3.30.tar.gz >> > >> > M:B generates a YAML file that contains >> > >> > ----snip---- >> > author: >> > - Tim Keefer <tk...@gm...> >> > Phil Crow <phi...@ya...> >> > ----snip---- >> >> In the current Module::Build::YAML, line 105, read: >> >> # XXX doesn't handle embedded newlines >> >> Shouldn't be so hard to fix... >> >> -- Johan >> >> >> ------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, >> security? >> Get stuff done quickly with pre-integrated technology to make your >> job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache >> Geronimo >> http://sel.as-us.falkag.net/sel? >> cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> Module-build-general mailing list >> Mod...@li... >> https://lists.sourceforge.net/lists/listinfo/module-build-general >> >> <mbyaml-patch.tar.gz> |