Skip to content

Commit

Permalink
fix support for domains with trailing dot in Mojo::URL
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 13, 2015
1 parent 9e6fe1c commit be9c197
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,10 +1,11 @@

6.24 2015-10-12
6.24 2015-10-13
- Improved session security by not storing secrets in the stash and making
CSRF tokens much harder to guess.
- Improved commands to show all options that can affect their behavior.
- Fixed bug in Mojo::JSON::Pointer that prevented JSON Pointers with trailing
slash from working correctly. (dolmen)
- Fixed support for domains with trailing dot in Mojo::URL.

6.23 2015-10-06
- Improved documentation browser CSS.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/URL.pm
Expand Up @@ -54,7 +54,7 @@ sub ihost {

# Decode
return $self->host(join '.',
map { /^xn--(.+)$/ ? punycode_decode($_) : $_ } split /\./, shift)
map { /^xn--(.+)$/ ? punycode_decode($_) : $_ } split(/\./, shift, -1))
if @_;

# Check if host needs to be encoded
Expand All @@ -63,8 +63,8 @@ sub ihost {

# Encode
return lc join '.',
map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split /\./,
$host;
map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ }
split(/\./, $host, -1);
}

sub is_abs { !!shift->scheme }
Expand Down
6 changes: 6 additions & 0 deletions t/mojo/url.t
Expand Up @@ -654,6 +654,12 @@ is $url->path->parts->[0], '100%_fun', 'right part';
is $url->path, '/100%25_fun', 'right path';
is "$url", 'http://mojolicio.us/100%25_fun', 'right format';

# Trailing dot
$url = Mojo::URL->new('http://☃.net./♥');
is $url->ihost, 'xn--n3h.net.', 'right internationalized host';
is $url->host, '☃.net.', 'right host';
is "$url", 'http://xn--n3h.net./%E2%99%A5', 'right format';

# No charset
$url = Mojo::URL->new;
$url->path->charset(undef);
Expand Down

0 comments on commit be9c197

Please sign in to comment.