Skip to content

Commit

Permalink
fixed another parse_header bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 1, 2013
1 parent 3612d80 commit 36e95c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -136,7 +136,7 @@ sub parse_header {
while ($str =~ s/^\s*([^=;, ]+)\s*//) {
push @token, $1, undef;
$token[-1] = unquote($1)
if $str =~ s/^=\s*("(?:\\\\|\\"|[^"])*"|[^;,]*)\s*//;
if $str =~ s/^=\s*("(?:\\\\|\\"|[^"])*"|[^;, ]*)\s*//;
# Separator
$str =~ s/^;\s*//;
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/cookie.t
Expand Up @@ -125,7 +125,7 @@ is $cookies->[1], undef, 'no more cookies';

# Parse multiple cookie request (RFC 2965)
$cookies = Mojo::Cookie::Request->parse(
'$Version=1; foo=bar; $Path=/test; baz=la la; $Path=/tset');
'$Version=1; foo=bar; $Path=/test; baz="la la"; $Path=/tset');
is $cookies->[0]->name, 'foo', 'right name';
is $cookies->[0]->value, 'bar', 'right value';
is $cookies->[1]->name, 'baz', 'right name';
Expand Down Expand Up @@ -170,7 +170,7 @@ is_deeply(Mojo::Cookie::Response->parse, [], 'no cookies');
# Parse response cookie (RFC 6265)
$cookies
= Mojo::Cookie::Response->parse(
'foo=ba r; Domain=example.com; Path=/test; Max-Age=60;'
'foo="ba r"; Domain=example.com; Path=/test; Max-Age=60;'
. ' Expires=Thu, 07 Aug 2008 07:07:59 GMT; Secure;');
is $cookies->[0]->name, 'foo', 'right name';
is $cookies->[0]->value, 'ba r', 'right value';
Expand All @@ -185,7 +185,7 @@ is $cookies->[1], undef, 'no more cookies';
# Parse response cookie with invalid flag (RFC 6265)
$cookies
= Mojo::Cookie::Response->parse(
'foo=ba r; Domain=example.com; Path=/test; Max-Age=60;'
'foo="ba r"; Domain=example.com; Path=/test; Max-Age=60;'
. ' Expires=Thu, 07 Aug 2008 07:07:59 GMT; InSecure;');
is $cookies->[0]->name, 'foo', 'right name';
is $cookies->[0]->value, 'ba r', 'right value';
Expand Down Expand Up @@ -362,11 +362,11 @@ is $cookies->[0]->to_string,
is $cookies->[1], undef, 'no more cookies';

# Parse response cookie with broken Expires value
$cookies = Mojo::Cookie::Response->parse('foo=ba r; Expires=Th');
$cookies = Mojo::Cookie::Response->parse('foo="ba r"; Expires=Th');
is $cookies->[0]->name, 'foo', 'right name';
is $cookies->[0]->value, 'ba r', 'right value';
is $cookies->[1], undef, 'no more cookies';
$cookies = Mojo::Cookie::Response->parse('foo=ba r; Expires=Th; Path=/test');
$cookies = Mojo::Cookie::Response->parse('foo="ba r"; Expires=Th; Path=/test');
is $cookies->[0]->name, 'foo', 'right name';
is $cookies->[0]->value, 'ba r', 'right value';
is $cookies->[1], undef, 'no more cookies';
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/util.t
Expand Up @@ -62,6 +62,8 @@ is get_line(\$buffer), undef, 'no line';
is_deeply parse_header(''), [], 'right result';
is_deeply parse_header('foo=;bar=""'), [['foo', '', 'bar', '']],
'right result';
is_deeply parse_header('foo=bar baz=yada'), [['foo', 'bar', 'baz', 'yada']],
'right result';
is_deeply parse_header('foo,bar,baz'),
[['foo', undef], ['bar', undef], ['baz', undef]], 'right result';
is_deeply parse_header('f "o" o , ba r'),
Expand All @@ -76,7 +78,7 @@ my $parsed = [['</foo/bar>', undef, 'rel', 'x', 't*', 'UTF-8\'de\'a%20b']];
is_deeply parse_header($header), $parsed, 'right result';
$header = 'a=b c; A=b.c; D=/E; a-b=3; F=Thu, 07 Aug 2008 07:07:59 GMT; Ab;';
$parsed = [
['a', 'b c', 'A', 'b.c', 'D', '/E', 'a-b', '3', 'F', 'Thu'],
['a', 'b', 'c', undef, 'A', 'b.c', 'D', '/E', 'a-b', '3', 'F', 'Thu'],
[
'07', undef, 'Aug', undef, '2008', undef,
'07:07:59', undef, 'GMT', undef, 'Ab', undef
Expand Down

0 comments on commit 36e95c6

Please sign in to comment.