Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow quoted cookie values, as per RFC 6265 #564

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/Plack/Request.pm
Expand Up @@ -68,7 +68,14 @@ sub cookies {
# trim leading trailing whitespace
$pair =~ s/^\s+//; $pair =~ s/\s+$//;

my ($key, $value) = map URI::Escape::uri_unescape($_), split( "=", $pair, 2 );
my ($key, $value) = split( "=", $pair, 2 );

$key = URI::Escape::uri_unescape($key);

# Values can be quoted
$value =~ s/\A"(.*)"\z/$1/;

$value = URI::Escape::uri_unescape($value);

# Take the first one like CGI.pm or rack do
$results{$key} = $value unless exists $results{$key};
Expand Down
22 changes: 21 additions & 1 deletion t/Plack-Request/cookie.t
Expand Up @@ -13,14 +13,34 @@ my $app = sub {
is $req->cookies->{Bar}, 'Baz';
is $req->cookies->{XXX}, 'Foo Bar';
is $req->cookies->{YYY}, 0, "When we get multiple values we return the first one (which e.g. Apache does too)";
is $req->cookies->{ZZZ}, 'spaced out';
is $req->cookies->{ZZTOP}, '"with quotes"';
is $req->cookies->{BOTH}, '"internal quotes"';
is $req->cookies->{EMPTYQUOTE}, '';
is $req->cookies->{EMPTY}, '';
is $req->cookies->{BADSTART}, '"data';
is $req->cookies->{BADEND}, 'data"';

$req->new_response(200)->finalize;
};

test_psgi $app, sub {
my $cb = shift;
my $req = HTTP::Request->new(GET => "/");
$req->header(Cookie => 'Foo=Bar; Bar=Baz; XXX=Foo%20Bar; YYY=0; YYY=3');
$req->header(Cookie => join(' ',
'Foo=Bar;',
'Bar=Baz;',
'XXX=Foo%20Bar;',
'YYY=0;',
'YYY=3;',
'ZZZ="spaced out";',
'ZZTOP=%22with%20quotes%22;',
'BOTH="%22internal quotes%22";',
'EMPTYQUOTE="";',
'EMPTY=;',
'BADSTART="data;',
'BADEND=data"',
));
$cb->($req);
};

Expand Down