[Catalyst-commits] r9899 - in HTTP-Request-AsCGI/trunk: . lib/HTTP/Request t

hdp at dev.catalyst.perl.org hdp at dev.catalyst.perl.org
Mon Apr 27 17:21:53 GMT 2009


Author: hdp
Date: 2009-04-27 18:21:52 +0100 (Mon, 27 Apr 2009)
New Revision: 9899

Added:
   HTTP-Request-AsCGI/trunk/t/02unescape.t
Modified:
   HTTP-Request-AsCGI/trunk/Changes
   HTTP-Request-AsCGI/trunk/lib/HTTP/Request/AsCGI.pm
   HTTP-Request-AsCGI/trunk/t/05env.t
Log:
reimplement PATH_INFO unescaping

Modified: HTTP-Request-AsCGI/trunk/Changes
===================================================================
--- HTTP-Request-AsCGI/trunk/Changes	2009-04-27 16:00:49 UTC (rev 9898)
+++ HTTP-Request-AsCGI/trunk/Changes	2009-04-27 17:21:52 UTC (rev 9899)
@@ -1,5 +1,8 @@
 This file documents the revision history for Perl extension HTTP::Request::AsCGI.
 
+0.9
+    - unescape PATH_INFO more safely
+
 0.8 2009-04-27
     - revert PATH_INFO change, Catalyst tests were failing
 

Modified: HTTP-Request-AsCGI/trunk/lib/HTTP/Request/AsCGI.pm
===================================================================
--- HTTP-Request-AsCGI/trunk/lib/HTTP/Request/AsCGI.pm	2009-04-27 16:00:49 UTC (rev 9898)
+++ HTTP-Request-AsCGI/trunk/lib/HTTP/Request/AsCGI.pm	2009-04-27 17:21:52 UTC (rev 9899)
@@ -9,6 +9,7 @@
 use HTTP::Response;
 use IO::Handle;
 use IO::File;
+use URI ();
 use URI::Escape ();
 
 __PACKAGE__->mk_accessors(qw[ environment request stdin stdout stderr ]);
@@ -24,6 +25,13 @@
 
 *enviroment = \&environment;
 
+my %reserved = map { sprintf('%02x', ord($_)) => 1 } split //, $URI::reserved;
+sub _uri_safe_unescape {
+    my ($s) = @_;
+    $s =~ s/%([a-fA-F0-9]{2})/$reserved{lc($1)} ? "%$1" : chr(hex($1))/ge;
+    $s;
+}
+
 sub new {
     my $class   = shift;
     my $request = shift;
@@ -50,8 +58,7 @@
         GATEWAY_INTERFACE => 'CGI/1.1',
         HTTP_HOST         => $uri->host_port,
         HTTPS             => ( $uri->scheme eq 'https' ) ? 'ON' : 'OFF',  # not in RFC 3875
-#        PATH_INFO         => URI::Escape::uri_unescape($uri->path),
-        PATH_INFO         => $uri->path,
+        PATH_INFO         => _uri_safe_unescape($uri->path),
         QUERY_STRING      => $uri->query || '',
         SCRIPT_NAME       => '/',
         SERVER_NAME       => $uri->host,

Added: HTTP-Request-AsCGI/trunk/t/02unescape.t
===================================================================
--- HTTP-Request-AsCGI/trunk/t/02unescape.t	                        (rev 0)
+++ HTTP-Request-AsCGI/trunk/t/02unescape.t	2009-04-27 17:21:52 UTC (rev 9899)
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use HTTP::Request::AsCGI;
+use Test::More tests => 1;
+
+is(
+  HTTP::Request::AsCGI::_uri_safe_unescape('%2Fhello%20there'),
+  '%2Fhello there',
+  'do not unescape reserved characters',
+);

Modified: HTTP-Request-AsCGI/trunk/t/05env.t
===================================================================
--- HTTP-Request-AsCGI/trunk/t/05env.t	2009-04-27 16:00:49 UTC (rev 9898)
+++ HTTP-Request-AsCGI/trunk/t/05env.t	2009-04-27 17:21:52 UTC (rev 9899)
@@ -8,7 +8,7 @@
 use HTTP::Request;
 use HTTP::Request::AsCGI;
 
-my $r = HTTP::Request->new( GET => 'http://www.host.com/cgi-bin/script.cgi/my%20path/?a=1&b=2', [ 'X-Test' => 'Test' ] );
+my $r = HTTP::Request->new( GET => 'http://www.host.com/cgi-bin/script.cgi/my%20path%2F?a=1&b=2', [ 'X-Test' => 'Test' ] );
 my %e = ( SCRIPT_NAME => '/cgi-bin/script.cgi' );
 my $c = HTTP::Request::AsCGI->new( $r, %e );
 $c->stdout(undef);
@@ -18,10 +18,7 @@
 is( $ENV{GATEWAY_INTERFACE}, 'CGI/1.1', 'GATEWAY_INTERFACE' );
 is( $ENV{HTTP_HOST}, 'www.host.com:80', 'HTTP_HOST' );
 is( $ENV{HTTP_X_TEST}, 'Test', 'HTTP_X_TEST' );
-TODO: {
-    local $TODO = 'backed out as it breaks Catalyst';
-    is( $ENV{PATH_INFO}, '/my path/', 'PATH_INFO' );
-}
+is( $ENV{PATH_INFO}, '/my path%2F', 'PATH_INFO' );
 is( $ENV{QUERY_STRING}, 'a=1&b=2', 'QUERY_STRING' );
 is( $ENV{SCRIPT_NAME}, '/cgi-bin/script.cgi', 'SCRIPT_NAME' );
 is( $ENV{REQUEST_METHOD}, 'GET', 'REQUEST_METHOD' );




More information about the Catalyst-commits mailing list