From 39817159a196a6acb7ce58266633ad6ea8490864 Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Sat, 19 Oct 2013 23:26:23 +0100 Subject: [PATCH] Imported Upstream version 0.17 --- Changes | 3 + MANIFEST | 4 +- META.yml | 2 +- MYMETA.json | 53 ---------- MYMETA.yml | 29 ------ README | 2 +- lib/URI/Template.pm | 14 ++- t/12-suite.t | 7 +- t/cases/extended-tests.json | 55 ++++++++++- t/cases/json2xml.xslt | 201 ++++++++++++++++++++++++++++++++++++++ t/cases/negative-tests.json | 33 ++++--- t/cases/transform-json-tests.xslt | 51 ++++++++++ 12 files changed, 347 insertions(+), 107 deletions(-) delete mode 100644 MYMETA.json delete mode 100644 MYMETA.yml create mode 100644 t/cases/json2xml.xslt create mode 100644 t/cases/transform-json-tests.xslt diff --git a/Changes b/Changes index 8c5b03e..a9677c3 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension URI::Template +0.17 2013-03-11 + - Special case return from empty hash and array values in query strings + 0.16 2012-05-30 - Conform to latest spec RFC 6570 (RT 66651) - Re-use test suite from official github repo diff --git a/MANIFEST b/MANIFEST index c09cc13..3f58770 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,8 +11,6 @@ lib/URI/Template.pm Makefile.PL MANIFEST This list of files META.yml -MYMETA.json -MYMETA.yml README t/01-use.t t/10-basic.t @@ -20,6 +18,8 @@ t/12-suite.t t/98-pod.t t/99-podcoverage.t t/cases/extended-tests.json +t/cases/json2xml.xslt t/cases/negative-tests.json t/cases/spec-examples-by-section.json t/cases/spec-examples.json +t/cases/transform-json-tests.xslt diff --git a/META.yml b/META.yml index e9316a4..fc3f038 100644 --- a/META.yml +++ b/META.yml @@ -27,4 +27,4 @@ requires: resources: license: http://dev.perl.org/licenses/ repository: http://github.com/bricas/uri-template -version: 0.16 +version: 0.17 diff --git a/MYMETA.json b/MYMETA.json deleted file mode 100644 index d3a923f..0000000 --- a/MYMETA.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "abstract" : "Object for handling URI templates (RFC 6570)", - "author" : [ - "=over 4" - ], - "dynamic_config" : 0, - "generated_by" : "Module::Install version 1.06, CPAN::Meta::Converter version 2.120921", - "license" : [ - "perl_5" - ], - "meta-spec" : { - "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", - "version" : "2" - }, - "name" : "URI-Template", - "no_index" : { - "directory" : [ - "inc", - "t" - ] - }, - "prereqs" : { - "build" : { - "requires" : { - "ExtUtils::MakeMaker" : "6.59", - "Test::More" : "0" - } - }, - "configure" : { - "requires" : { - "ExtUtils::MakeMaker" : "6.59" - } - }, - "runtime" : { - "requires" : { - "URI" : "0", - "URI::Escape" : "0", - "Unicode::Normalize" : "0", - "perl" : "5.006" - } - } - }, - "release_status" : "stable", - "resources" : { - "license" : [ - "http://dev.perl.org/licenses/" - ], - "repository" : { - "url" : "http://github.com/bricas/uri-template" - } - }, - "version" : "0.16" -} diff --git a/MYMETA.yml b/MYMETA.yml deleted file mode 100644 index 8874d8b..0000000 --- a/MYMETA.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -abstract: 'Object for handling URI templates (RFC 6570)' -author: - - '=over 4' -build_requires: - ExtUtils::MakeMaker: 6.59 - Test::More: 0 -configure_requires: - ExtUtils::MakeMaker: 6.59 -dynamic_config: 0 -generated_by: 'Module::Install version 1.06, CPAN::Meta::Converter version 2.120921' -license: perl -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 -name: URI-Template -no_index: - directory: - - inc - - t -requires: - URI: 0 - URI::Escape: 0 - Unicode::Normalize: 0 - perl: 5.006 -resources: - license: http://dev.perl.org/licenses/ - repository: http://github.com/bricas/uri-template -version: 0.16 diff --git a/README b/README index 6de3191..0010981 100644 --- a/README +++ b/README @@ -49,7 +49,7 @@ AUTHORS * Ricardo SIGNES COPYRIGHT AND LICENSE - Copyright 2007-2012 by Brian Cassidy + Copyright 2007-2013 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/lib/URI/Template.pm b/lib/URI/Template.pm index 79c944f..390f6a6 100644 --- a/lib/URI/Template.pm +++ b/lib/URI/Template.pm @@ -3,7 +3,7 @@ package URI::Template; use strict; use warnings; -our $VERSION = '0.16'; +our $VERSION = '0.17'; use URI; use URI::Escape (); @@ -123,7 +123,10 @@ sub _tostring_query { $join = '&' if $exp->{ op } =~ /[?&]/; if ( ref $value eq 'ARRAY' ) { - return unless @$value; + if( !@$value ) { + return if $var->{ explode }; + return $var->{ name } . '='; + } if ( $var->{ explode } ) { return join( $join, map { $var->{ name } . '=' . _quote( $_, $safe ) } @$value ); @@ -134,7 +137,10 @@ sub _tostring_query { } } elsif ( ref $value eq 'HASH' ) { - return unless keys %$value; + if( !keys %$value ) { + return if $var->{ explode }; + return $var->{ name } . '='; + } if ( $var->{ explode } ) { return join( $join, @@ -387,7 +393,7 @@ URI object. =head1 COPYRIGHT AND LICENSE -Copyright 2007-2012 by Brian Cassidy +Copyright 2007-2013 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/t/12-suite.t b/t/12-suite.t index cbe2869..3a763be 100644 --- a/t/12-suite.t +++ b/t/12-suite.t @@ -7,6 +7,10 @@ use Scalar::Util (); BEGIN { eval "use JSON ();"; plan skip_all => "JSON required" if $@; + + eval { JSON->VERSION( 2 ) }; + plan skip_all => "JSON version 2 of greater required" if $@; + plan( 'no_plan' ); use_ok( 'URI::Template' ); } @@ -23,8 +27,7 @@ for my $file ( @files ) { my $data = do { local $/; <$json> }; close( $json ); - eval { JSON->VERSION( 2 ) }; - my $suite = $@ ? JSON::jsonToObj( $data ) : JSON::from_json( $data ); + my $suite = JSON->new->utf8( 1 )->decode( $data ); for my $name ( sort keys %$suite ) { my $info = $suite->{ $name }; diff --git a/t/cases/extended-tests.json b/t/cases/extended-tests.json index ab6dc4c..959840e 100644 --- a/t/cases/extended-tests.json +++ b/t/cases/extended-tests.json @@ -12,7 +12,18 @@ "geocode" : ["37.76","-122.427"], "first_name" : "John", "last.name" : "Doe", - "Some%20Thing" : "foo" + "Some%20Thing" : "foo", + "number" : 6, + "long" : 37.76, + "lat" : -122.427, + "group_id" : "12345", + "query" : "PREFIX dc: SELECT ?book ?who WHERE { ?book dc:creator ?who }", + "uri" : "http://example.org/?uri=http%3A%2F%2Fexample.org%2F", + "word" : "drücken", + "Stra%C3%9Fe" : "Grüner Weg", + "random" : "šö䟜ñꀣ¥‡ÑÒÓÔÕÖ×ØÙÚàáâãäåæçÿ", + "assoc_special_chars" : + { "šö䟜ñꀣ¥‡ÑÒÓÔÕ" : "Ö×ØÙÚàáâãäåæçÿ" } }, "testcases":[ @@ -29,7 +40,16 @@ [ "/search.json?q=URI%20Templates&geocode=37.76,-122.427&lang=en&page=5", "/search.json?q=URI%20Templates&geocode=-122.427,37.76&lang=en&page=5"] ], - ["/test{/Some%20Thing}", "/test/foo" ] + ["/test{/Some%20Thing}", "/test/foo" ], + ["/set{?number}", "/set?number=6"], + ["/loc{?long,lat}" , "/loc?long=37.76&lat=-122.427"], + ["/base{/group_id,first_name}/pages{/page,lang}{?format,q}","/base/12345/John/pages/5/en?format=json&q=URI%20Templates"], + ["/sparql{?query}", "/sparql?query=PREFIX%20dc%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%20SELECT%20%3Fbook%20%3Fwho%20WHERE%20%7B%20%3Fbook%20dc%3Acreator%20%3Fwho%20%7D"], + ["/go{?uri}", "/go?uri=http%3A%2F%2Fexample.org%2F%3Furi%3Dhttp%253A%252F%252Fexample.org%252F"], + ["/service{?word}", "/service?word=dr%C3%BCcken"], + ["/lookup{?Stra%C3%9Fe}", "/lookup?Stra%C3%9Fe=Gr%C3%BCner%20Weg"], + ["{random}" , "%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"], + ["{?assoc_special_chars*}", "?%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95=%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"] ] }, "Additional Examples 2":{ @@ -63,5 +83,36 @@ "/albums/person?fields=name,id,picture&token=12345"] ] ] + }, + "Additional Examples 3: Empty Variables":{ + "variables" : { + "empty_list" : [], + "empty_assoc" : {} + }, + "testcases":[ + [ "{/empty_list}", [ "" ] ], + [ "{/empty_list*}", [ "" ] ], + [ "{?empty_list}", [ "?empty_list="] ], + [ "{?empty_list*}", [ "" ] ], + [ "{?empty_assoc}", [ "?empty_assoc=" ] ], + [ "{?empty_assoc*}", [ "" ] ] + ] + }, + "Additional Examples 4: Numeric Keys":{ + "variables" : { + "42" : "The Answer to the Ultimate Question of Life, the Universe, and Everything", + "1337" : ["leet", "as","it", "can","be"], + "german" : { + "11": "elf", + "12": "zwölf" + } + }, + "testcases":[ + [ "{42}", "The%20Answer%20to%20the%20Ultimate%20Question%20of%20Life%2C%20the%20Universe%2C%20and%20Everything"], + [ "{?42}", "?42=The%20Answer%20to%20the%20Ultimate%20Question%20of%20Life%2C%20the%20Universe%2C%20and%20Everything"], + [ "{1337}", "leet,as,it,can,be"], + [ "{?1337*}", "?1337=leet&1337=as&1337=it&1337=can&1337=be"], + [ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf"] ] + ] } } diff --git a/t/cases/json2xml.xslt b/t/cases/json2xml.xslt new file mode 100644 index 0000000..59b3548 --- /dev/null +++ b/t/cases/json2xml.xslt @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \b + + + + + + + + + + + \v + + + + + \f + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/t/cases/negative-tests.json b/t/cases/negative-tests.json index aa41464..dca9c9e 100644 --- a/t/cases/negative-tests.json +++ b/t/cases/negative-tests.json @@ -2,17 +2,21 @@ "Failure Tests":{ "level":4, "variables":{ - "id" : "thing", - "var" : "value", - "hello" : "Hello World!", - "empty" : "", - "path" : "/foo/bar", - "x" : "1024", - "y" : "768", - "list" : ["red", "green", "blue"], - "keys" : { "semi" : ";", "dot" : ".", "comma" : ","}, - "example" : "red", - "searchTerms" : "uri templates" + "id" : "thing", + "var" : "value", + "hello" : "Hello World!", + "empty" : "", + "path" : "/foo/bar", + "x" : "1024", + "y" : "768", + "list" : ["red", "green", "blue"], + "keys" : { "semi" : ";", "dot" : ".", "comma" : ","}, + "example" : "red", + "searchTerms" : "uri templates", + "~thing" : "some-user", + "default-graph-uri" : ["http://www.example/book/","http://www.example/papers/"], + "query" : "PREFIX dc: SELECT ?book ?who WHERE { ?book dc:creator ?who }" + }, "testcases":[ [ "{/id*", false ], @@ -32,11 +36,14 @@ [ "x{?empty|foo=none}" , false ], [ "/h{#hello+}" , false ], [ "/h#{hello+}" , false ], - [ "/vars/:var" , false ], [ "{keys:1}", false ], [ "{+keys:1}", false ], [ "{;keys:1*}", false ], - [ "?{-join|&|var,list}" , false ] + [ "?{-join|&|var,list}" , false ], + [ "/people/{~thing}", false], + [ "/sparql{?query){&default-graph-uri*}", false ], + [ "/resolution{?x, y}" , false ] + ] } } \ No newline at end of file diff --git a/t/cases/transform-json-tests.xslt b/t/cases/transform-json-tests.xslt new file mode 100644 index 0000000..d956b6b --- /dev/null +++ b/t/cases/transform-json-tests.xslt @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.11.0