Re: [Module::Build] broken META.yml file
Status: Beta
Brought to you by:
kwilliams
From: Stephen A. <spa...@gm...> - 2006-05-12 04:50:57
|
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 ca= se I did the patch wrong. Stephen spadkins@pompeii:/usr/rubicon/spadkins/src/app/Module-Build> svn diff Index: t/mbyaml.t =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- t/mbyaml.t (revision 6288) +++ t/mbyaml.t (working copy) @@ -9,9 +9,12 @@ $dir =3D "t" if (-d "t"); { - use_ok("Module::Build::YAML"); - my ($expected, $got, $var); - $var =3D { + use_ok("Module::Build::YAML"); + my ($expected, $got, $var); + ########################################################## + # Test a typical-looking Module::Build structure (alphabetized) + ########################################################## + $var =3D { 'resources' =3D> { 'license' =3D> 'http://opensource.org/licenses/artistic-license.php' }, @@ -43,11 +46,11 @@ }, 'abstract' =3D> 'A framework for building dynamic widgets or full applications in Javascript' }; - $expected =3D <<EOF; + $expected =3D <<'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 =3D &Module::Build::YAML::Dump($var); is($got, $expected, "Dump(): single deep hash"); - $expected =3D <<EOF; + ########################################################## + # Test a typical-looking Module::Build structure (ordered) + ########################################################## + $expected =3D <<'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 =3D &Module::Build::YAML::Dump($var); is($got, $expected, "Dump(): single deep hash, ordered"); + ########################################################## + # Test that an array turns into multiple documents + ########################################################## $var =3D [ "e", 2.71828, [ "pi", "is", 3.1416 ], { fun =3D> "under_sun", 6 =3D> undef, "more", undef }, ]; - $expected =3D <<EOF; + $expected =3D <<'EOF'; --- e --- @@ -118,14 +127,17 @@ - is - 3.1416 --- -6: "" +6: ~ fun: under_sun -more: "" +more: ~ EOF $got =3D &Module::Build::YAML::Dump(@$var); is($got, $expected, "Dump(): multiple, various"); - $expected =3D <<EOF; + ########################################################## + # Test that a single array ref turns into one document + ########################################################## + $expected =3D <<'EOF'; --- - e - 2.71828 @@ -134,16 +146,115 @@ - is - 3.1416 - - 6: "" + 6: ~ fun: under_sun - more: "" + more: ~ EOF $got =3D &Module::Build::YAML::Dump($var); is($got, $expected, "Dump(): single array of various"); + ########################################################## + # Test Object-Oriented Flavor of the API + ########################################################## my $y =3D Module::Build::YAML->new(); $got =3D $y->Dump($var); is($got, $expected, "Dump(): single array of various (OO)"); + + ########################################################## + # Test Quoting Conditions (newlines, quotes, tildas, undefs) + ########################################################## + $var =3D { + 'foo01' =3D> '`~!@#$%^&*()_+-=3D{}|[]\\;\':",./?<> +<nl>', + 'foo02' =3D> '~!@#$%^&*()_+-=3D{}|[]\\;:,./<>?', + 'foo03' =3D> undef, + 'foo04' =3D> '~', + }; + $expected =3D <<'EOF'; +--- +foo01: "`~!@#$%^&*()_+-=3D{}|[]\;':\",./?<>\n<nl>" +foo02: "~!@#$%^&*()_+-=3D{}|[]\;:,./<>?" +foo03: ~ +foo04: "~" +EOF + $got =3D &Module::Build::YAML::Dump($var); + is($got, $expected, "Dump(): tricky embedded characters"); + + $var =3D { + 'foo10' =3D> undef, + 'foo40' =3D> '!', + 'foo41' =3D> '@', + 'foo42' =3D> '#', + 'foo43' =3D> '$', + 'foo44' =3D> '%', + 'foo45' =3D> '^', + 'foo47' =3D> '&', + 'foo48' =3D> '*', + 'foo49' =3D> '(', + 'foo50' =3D> ')', + 'foo51' =3D> '_', + 'foo52' =3D> '+', + 'foo53' =3D> '-', + 'foo54' =3D> '=3D', + 'foo55' =3D> '{', + 'foo56' =3D> '}', + 'foo57' =3D> '|', + 'foo58' =3D> '[', + 'foo59' =3D> ']', + 'foo60' =3D> '\\', + 'foo61' =3D> ';', + 'foo62' =3D> ':', + 'foo63' =3D> ',', + 'foo64' =3D> '.', + 'foo65' =3D> '/', + 'foo66' =3D> '<', + 'foo67' =3D> '>', + 'foo68' =3D> '?', + 'foo69' =3D> '\'', + 'foo70' =3D> '"', + 'foo71' =3D> '`', + 'foo72' =3D> ' +', + }; + $expected =3D <<'EOF'; +--- +foo10: ~ +foo40: "!" +foo41: '@' +foo42: "#" +foo43: $ +foo44: % +foo45: "^" +foo47: "&" +foo48: "*" +foo49: "(" +foo50: ")" +foo51: _ +foo52: + +foo53: - +foo54: =3D +foo55: "{" +foo56: "}" +foo57: "|" +foo58: "[" +foo59: "]" +foo60: \ +foo61: ; +foo62: : +foo63: , +foo64: . +foo65: / +foo66: '<' +foo67: '>' +foo68: "?" +foo69: "'" +foo70: '"' +foo71: "`" +foo72: "\n" +EOF + $got =3D &Module::Build::YAML::Dump($var); + is($got, $expected, "Dump(): tricky embedded characters (singles)"); + } Index: lib/Module/Build/YAML.pm =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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) =3D @_; - # 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 =3D~ /["'`~\n!\@\#^\&\*\(\)\{\}\[\]\|<>\?]/) { + if ($value !~ /['`~\n!\#^\&\*\(\)\{\}\[\]\|\?]/) { # nothing but " or @ or < or > (email addresses) + return("'" . $value . "'"); + } + else { + $value =3D~ s/\n/\\n/g; # handle embedded newlines + $value =3D~ s/"/\\"/g; # handle embedded quotes + return('"' . $value . '"'); + } + } # allow simple scalars (without embedded quote chars) to be unquoted - elsif ($value !~ /["'\\]/) { + # (includes $%_+=3D-\;:,./) + else { return($value); } - # strings without double-quotes get double-quoted - elsif ($value !~ /\"/) { - $value =3D~ s{\\}{\\\\}g; - return qq{"$value"}; - } - # other strings get single-quoted - else { - $value =3D~ s{([\\'])}{\\$1}g; - return qq{'$value'}; - } } 1; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D On 5/11/06, Johan Vromans <jvr...@sq...> wrote: > and...@fr... (Andreas J. Koenig) writes: > > >>>>>> On Wed, 10 May 2006 08:40:33 +0200, andreas.koenig.gmwojprw@franz.= ak.mind.de (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 ea= sier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Module-build-general mailing list > Mod...@li... > https://lists.sourceforge.net/lists/listinfo/module-build-general > |