Imported upstream version 0.08.01 upstream/0.08.01
authorIan Beckwith <ianb@erislabs.net>
Sat, 1 Mar 2008 00:35:06 +0000 (00:35 +0000)
committerIan Beckwith <ianb@erislabs.net>
Sat, 1 Mar 2008 00:35:06 +0000 (00:35 +0000)
Changes
META.yml
README
lib/URI/Template.pm
t/10-basic.t

diff --git a/Changes b/Changes
index 41e12ef..c645e22 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension URI::Template
 
+0.08_01 Sun Jul 29 2007
+    - handle new escaping rules from the latest spec.
+
 0.07  Thu May 24 2007
     - allow the user to pass an array ref to process and process_to_string
       which fills values by position
index 6fcf3f2..199dac4 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 ---
 name: URI-Template
-version: 0.07
+version: 0.08_01
 author:
   - 'Brian Cassidy <brian.cassidy@nald.ca>'
 abstract: Object for handling URI templates
@@ -12,7 +12,7 @@ requires:
 provides:
   URI::Template:
     file: lib/URI/Template.pm
-    version: 0.07
+    version: 0.08_01
 generated_by: Module::Build version 0.2808
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html
diff --git a/README b/README
index 59f5a76..b07c19f 100644 (file)
--- a/README
+++ b/README
@@ -13,7 +13,7 @@ SYNOPSIS
 DESCRIPTION
     This is an initial attempt to provide a wrapper around URI templates as
     described at
-    http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-00.txt
+    http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-01.txt
 
 INSTALLATION
     To install this module via Module::Build:
index 47cfb2b..4f5cbfc 100644 (file)
@@ -3,12 +3,14 @@ package URI::Template;
 use strict;
 use warnings;
 
-our $VERSION = '0.07';
+our $VERSION = '0.08_01';
 
 use URI;
 use URI::Escape ();
 use overload '""' => \&as_string;
 
+my $unsafe = q(^A-Za-z0-9\-_.~!\$\&'()*+,;=:/?\[\]#@);
+
 =head1 NAME
 
 URI::Template - Object for handling URI templates
@@ -26,7 +28,7 @@ URI::Template - Object for handling URI templates
 =head1 DESCRIPTION
 
 This is an initial attempt to provide a wrapper around URI templates
-as described at http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-00.txt
+as described at http://www.ietf.org/internet-drafts/draft-gregorio-uritemplate-01.txt
 
 =head1 INSTALLATION
 
@@ -138,7 +140,7 @@ sub _process_by_key {
     # fix undef vals
     for my $var ( @vars ) {
         $params{ $var } = defined $params{ $var }
-            ? URI::Escape::uri_escape( $params{ $var } )
+            ? URI::Escape::uri_escape( $params{ $var }, $unsafe )
             : '';
     }
 
@@ -156,7 +158,7 @@ sub _process_by_position {
 
     $uri =~ s/{(.+?)}/@params
         ? defined $params[ 0 ]
-            ? URI::Escape::uri_escape( shift @params )
+            ? URI::Escape::uri_escape( shift @params, $unsafe )
             : ''
         : ''/eg;
 
index 4240367..7dc6308 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 25;
 
 use_ok( 'URI::Template' );
 
@@ -52,6 +52,71 @@ use_ok( 'URI::Template' );
     }
 }
 
+# test from spec
+{
+    my %vals = (
+        a => 'fred',
+        b => 'barney',
+        c => 'cheeseburger',
+        d => 'one two three',
+        e => '20% tricky',
+        f => '',
+        20 => 'this-is-spinal-tap',
+        scheme => 'https',
+        p => 'quote=to+be+or+not+to+be',
+        q => 'hullo#world',
+    );
+
+    my @urls = (
+        [ (
+            'http://example.org/page1#{a}',
+            'http://example.org/page1#fred',
+        ) ],
+        [ (
+            'http://example.org/{a}/{b}/',
+            'http://example.org/fred/barney/',
+        ) ],
+        [ (
+            'http://example.org/{a}{b}/',
+            'http://example.org/fredbarney/',
+        ) ],
+        [ (
+            'http://example.com/order/{c}/{c}/{c}/',
+            'http://example.com/order/cheeseburger/cheeseburger/cheeseburger/',
+        ) ],
+        [ (
+            'http://example.org/{d}',
+            'http://example.org/one%20two%20three',
+        ) ],
+        [ (
+            'http://example.org/{e}',
+            'http://example.org/20%25%20tricky',
+        ) ],
+        [ (
+            'http://example.com/{f}/',
+            'http://example.com//',
+        ) ],
+        [ (
+            '{scheme}://{20}.example.org?date={wilma}&option={a}',
+            'https://this-is-spinal-tap.example.org?date=&option=fred',
+        ) ],
+        [ (
+            'http://example.org?{p}',
+            'http://example.org?quote=to+be+or+not+to+be',
+        ) ],
+        [ (
+            'http://example.com/{q}',
+            'http://example.com/hullo#world',
+        ) ],
+    );
+
+    for my $list ( @urls ) {
+        my $template = URI::Template->new( $list->[ 0 ] );
+        my $result = $template->process( %vals );
+        is( $result, $list->[ 1 ], 'escaped properly' );
+    }
+}
+
 {
     my $template = URI::Template->new( 'http://foo.com/{z}/{z}/' );
     is_deeply( [ $template->variables ], [ 'z' ], 'unique vars' );