Skip to content

Commit

Permalink
fixed another domain detection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 13, 2013
1 parent ea5c332 commit 36042c6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.79 2013-01-13
- Fixed small domain detection bug in Mojo::UserAgent::CookieJar.

3.78 2013-01-13
- Added to_dir method to Mojo::Path.
- Improved documentation.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -48,6 +48,7 @@ sub extract {
my $domain = lc($cookie->domain // $host);
$domain =~ s/^\.//;
next unless $host eq $domain || $host =~ /\Q.$domain\E$/;
next if $host =~ /\.\d+$/;
$cookie->domain($domain);

# Validate path
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -40,7 +40,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.78';
our $VERSION = '3.79';

sub AUTOLOAD {
my $self = shift;
Expand Down
48 changes: 48 additions & 0 deletions t/mojo/cookiejar.t
Expand Up @@ -317,6 +317,30 @@ $tx->req->url->parse('http://mojolicio.us/whatever');
$jar->inject($tx);
is $tx->req->cookie('foo'), undef, 'no cookie';

# Extract and inject cookies for "localhost" (valid and invalid)
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://localhost:3000');
$tx->res->cookies(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'local',
domain => 'localhost'
),
Mojo::Cookie::Response->new(
name => 'bar',
value => 'local',
domain => 'bar.localhost'
)
);
$jar->extract($tx);
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://localhost:8080');
$jar->inject($tx);
is $tx->req->cookie('foo')->name, 'foo', 'right name';
is $tx->req->cookie('foo')->value, 'local', 'right value';
is $tx->req->cookie('bar'), undef, 'no cookie';

# Extract and inject cookies with domain and path
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
Expand Down Expand Up @@ -377,6 +401,30 @@ $tx->res->cookies(
$jar->extract($tx);
is_deeply [$jar->all], [], 'no cookies';

# Extract cookies with invalid domain (IP address)
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
$tx->req->url->parse('http://213.133.102.53/perldoc/Mojolicious');
$tx->res->cookies(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'invalid',
domain => '213.133.102.53'
),
Mojo::Cookie::Response->new(
name => 'foo',
value => 'invalid',
domain => '102.53'
),
Mojo::Cookie::Response->new(
name => 'foo',
value => 'invalid',
domain => '53'
)
);
$jar->extract($tx);
is_deeply [$jar->all], [], 'no cookies';

# Extract cookies with invalid path
$jar = Mojo::UserAgent::CookieJar->new;
$tx = Mojo::Transaction::HTTP->new;
Expand Down

0 comments on commit 36042c6

Please sign in to comment.