HTTP::Body, Patch from Tom Heady to fix urlencoded parser to handle spaces after...
Andy Grundman [Sat, 23 Feb 2008 15:07:19 +0000 (15:07 +0000)]
12 files changed:
Changes
lib/HTTP/Body/UrlEncoded.pm
t/05urlencoded.t
t/data/urlencoded/004-content.dat [new file with mode: 0644]
t/data/urlencoded/004-headers.yml [new file with mode: 0644]
t/data/urlencoded/004-results.yml [new file with mode: 0644]
t/data/urlencoded/005-content.dat [new file with mode: 0644]
t/data/urlencoded/005-headers.yml [new file with mode: 0644]
t/data/urlencoded/005-results.yml [new file with mode: 0644]
t/data/urlencoded/006-content.dat [new file with mode: 0644]
t/data/urlencoded/006-headers.yml [new file with mode: 0644]
t/data/urlencoded/006-results.yml [new file with mode: 0644]

diff --git a/Changes b/Changes
index 5965ddc..80d9c5d 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@ This file documents the revision history for Perl extension HTTP::Body.
 
 1.00
         - Added support for chunked requests if no $length value is passed to new().
+        - Fixed urlencoded parser to handle spaces after semicolons and equal signs
+          in the value. (Tom Heady, http://rt.cpan.org/Ticket/Display.html?id=31055)
 
 0.9   2007-03-27 14:00:00
         - Fixed bug where empty fields in multipart/form-data were ignored.
index 3d32562..671ba47 100644 (file)
@@ -45,9 +45,9 @@ sub spin {
     # Note: s/// appears faster than tr///
     $self->{buffer} =~ s/\+/ /g;
 
-    for my $pair ( split( /[&;]/, $self->{buffer} ) ) {
+    for my $pair ( split( /&|;(?:\s+)?/, $self->{buffer} ) ) {
 
-        my ( $name, $value ) = split( /=/, $pair );
+        my ( $name, $value ) = split( /=/, $pair , 2 );
 
         next unless defined $name;
         next unless defined $value;
index ef92262..5880c06 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 31;
 
 use Cwd;
 use Digest::MD5 qw(md5_hex);
@@ -14,7 +14,7 @@ use YAML;
 
 my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
 
-for ( my $i = 1; $i <= 3; $i++ ) {
+for ( my $i = 1; $i <= 6; $i++ ) {
 
     my $test    = sprintf( "%.3d", $i );
     my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
diff --git a/t/data/urlencoded/004-content.dat b/t/data/urlencoded/004-content.dat
new file mode 100644 (file)
index 0000000..7f4970a
--- /dev/null
@@ -0,0 +1 @@
+one=foo; two=bar
diff --git a/t/data/urlencoded/004-headers.yml b/t/data/urlencoded/004-headers.yml
new file mode 100644 (file)
index 0000000..203c3f6
--- /dev/null
@@ -0,0 +1,4 @@
+---
+Content-Length: 16
+Content-Type: application/x-www-form-urlencoded
+User-Agent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'
diff --git a/t/data/urlencoded/004-results.yml b/t/data/urlencoded/004-results.yml
new file mode 100644 (file)
index 0000000..23e78de
--- /dev/null
@@ -0,0 +1,6 @@
+---
+body: ~
+param:
+  one: foo
+  two: bar
+upload: {}
diff --git a/t/data/urlencoded/005-content.dat b/t/data/urlencoded/005-content.dat
new file mode 100644 (file)
index 0000000..94675fb
--- /dev/null
@@ -0,0 +1 @@
+one=foo;two=bar
diff --git a/t/data/urlencoded/005-headers.yml b/t/data/urlencoded/005-headers.yml
new file mode 100644 (file)
index 0000000..9377827
--- /dev/null
@@ -0,0 +1,4 @@
+---
+Content-Length: 15
+Content-Type: application/x-www-form-urlencoded
+User-Agent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'
diff --git a/t/data/urlencoded/005-results.yml b/t/data/urlencoded/005-results.yml
new file mode 100644 (file)
index 0000000..23e78de
--- /dev/null
@@ -0,0 +1,6 @@
+---
+body: ~
+param:
+  one: foo
+  two: bar
+upload: {}
diff --git a/t/data/urlencoded/006-content.dat b/t/data/urlencoded/006-content.dat
new file mode 100644 (file)
index 0000000..1438372
--- /dev/null
@@ -0,0 +1 @@
+one=foo;two=bar=bam
diff --git a/t/data/urlencoded/006-headers.yml b/t/data/urlencoded/006-headers.yml
new file mode 100644 (file)
index 0000000..ce69c82
--- /dev/null
@@ -0,0 +1,4 @@
+---
+Content-Length: 19
+Content-Type: application/x-www-form-urlencoded
+User-Agent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'
diff --git a/t/data/urlencoded/006-results.yml b/t/data/urlencoded/006-results.yml
new file mode 100644 (file)
index 0000000..ccfab1f
--- /dev/null
@@ -0,0 +1,6 @@
+---
+body: ~
+param:
+  one: foo
+  two: bar=bam
+upload: {}