Skip to content

Commit

Permalink
Fix bug with whitespace trimming of cookie elements
Browse files Browse the repository at this point in the history
    The whitespace behavior is now identical to CGI::Simple::Cookie, and
    has an automated test.
  • Loading branch information
markstos committed Jan 2, 2011
1 parent f36ac93 commit 99452f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- CGI::Cookie->new() now follows the documentation and returns undef
if the -name and -value args aren't provided. This new behavior is also
consistent with the docs and code of CGI::Simple::Cookie. (Mark Stosberg)
- CGI::Cookie->parse() now trims leading and trailing whitespace from cookie
elements as intended. The change also makes this part of the parsing
identical to CGI::Simple::Cookie (Mark Stosberg)

[SECURITY]
- Further improvements have been made to guard against newline injections
Expand Down
4 changes: 3 additions & 1 deletion lib/CGI/Cookie.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ sub parse {

my @pairs = split("[;,] ?",$raw_cookie);
for (@pairs) {
s/\s*(.*?)\s*/$1/;
s/^\s+//;
s/\s+$//;

my($key,$value) = split("=",$_,2);

# Some foreign cookies are not in name=value format, so ignore
Expand Down
3 changes: 2 additions & 1 deletion t/cookie.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use CGI::Cookie;
#-----------------------------------------------------------------------------

my @test_cookie = (
'foo=123; bar=qwerty; baz=wibble; qux=a1',
# including leading and trailing whitespace in first cookie
' foo=123 ; bar=qwerty; baz=wibble; qux=a1',
'foo=123; bar=qwerty; baz=wibble;',
'foo=vixen; bar=cow; baz=bitch; qux=politician',
'foo=a%20phrase; bar=yes%2C%20a%20phrase; baz=%5Ewibble; qux=%27',
Expand Down

0 comments on commit 99452f4

Please sign in to comment.