Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed host normalization bug in Mojo::URL
  • Loading branch information
kraih committed Apr 22, 2013
1 parent c27ad6c commit 8db967e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -7,6 +7,7 @@
- Improved default descriptions in Test::Mojo.
- Improved documentation.
- Improved tests.
- Fixed host normalization bug in Mojo::URL.
- Fixed small html_unescape bug in Mojo::Util.
- Fixed small encoding bug in routes command.
- Fixed a few small clone bugs.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/URL.pm
Expand Up @@ -67,7 +67,7 @@ sub ihost {
return lc $host unless $host =~ /[^\x00-\x7f]/;

# Encode
return join '.',
return lc join '.',
map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split /\./,
$host;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -43,7 +43,7 @@ sub extract {
for my $cookie (@{$tx->res->cookies}) {

# Validate domain
my $host = lc $url->ihost;
my $host = $url->ihost;
my $domain = lc($cookie->domain // $host);
$domain =~ s/^\.//;
next
Expand All @@ -61,7 +61,7 @@ sub extract {
sub find {
my ($self, $url) = @_;

return unless my $domain = lc($url->ihost // '');
return unless my $domain = $url->ihost;
my $path = $url->path->to_abs_string;
my @found;
while ($domain =~ /[^.]+\.[^.]+|localhost$/) {
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/url.t
Expand Up @@ -421,10 +421,10 @@ is $url->path->parts->[0], '♥', 'right path part';
is $url->path, '/%E2%99%A5/', 'right path';
is $url->query, 'q=%E2%99%A5%E2%98%83', 'right query';
is $url->query->param('q'), '♥☃', 'right query value';
$url = Mojo::URL->new('http://☃.net/♥/♥/?♥=☃');
$url = Mojo::URL->new('http://☃.Net/♥/♥/?♥=☃');
ok $url->is_abs, 'is absolute';
is $url->scheme, 'http', 'right scheme';
is $url->host, '☃.net', 'right host';
is $url->host, '☃.Net', 'right host';
is $url->ihost, 'xn--n3h.net', 'right internationalized host';
is $url->path, '/%E2%99%A5/%E2%99%A5/', 'right path';
is $url->path->parts->[0], '', 'right path part';
Expand Down

0 comments on commit 8db967e

Please sign in to comment.