From 79c81e365d7d5906792ca35a33c94e759c00ae03 Mon Sep 17 00:00:00 2001
From: Nigel Kukard <nkukard@lbsd.net>
Date: Sun, 29 Dec 2013 11:43:51 +0000
Subject: [PATCH] Better support for parsing form content

---
 opentrafficshaper/utils.pm | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/opentrafficshaper/utils.pm b/opentrafficshaper/utils.pm
index 0a0b338..9252ae1 100644
--- a/opentrafficshaper/utils.pm
+++ b/opentrafficshaper/utils.pm
@@ -92,10 +92,18 @@ sub parseFormContent
 	# Split information into name/value pairs
 	my @pairs = split(/&/, $data);
 	foreach my $pair (@pairs) {
+		# Spaces are represented by +'s
+		$pair =~ tr/+/ /;
+		# Split off name value pairs
 		my ($name, $value) = split(/=/, $pair);
-		$value =~ tr/+/ /;
-		$value =~ s/%(..)/pack("C", hex($1))/eg;
-		$res{$name} = $value;
+		# Unescape name value pair
+		$name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+		$value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+		# Cleanup...
+		$name =~ s/[^0-9A-Za-z\[\]\.]/_/g;
+		# Add to hash
+		$res{$name}->{'value'} = $value;
+		push(@{$res{$name}->{'values'}},$value);
 	}
 
 	return \%res;
-- 
GitLab