Skip to content

Commit

Permalink
fixed a few more Mojo::URL bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 30, 2014
1 parent b736b64 commit cb97c26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -2,7 +2,9 @@
5.71 2014-12-30
- Updated Net::DNS::Native requirement to 0.15 for some important bug fixes.
- Updated jQuery to version 2.1.3.
- Improved Mojo::URL performance.
- Fixed fragment and userinfo normalization bugs in Mojo::URL.
- Fixed query charset bug in Mojo::URL.

5.70 2014-12-18
- Improved Mojo::Template performance.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/URL.pm
Expand Up @@ -93,8 +93,7 @@ sub path {
return $self->{path} unless @_;

# New path
my $path = shift;
$self->{path} = ref $path ? $path : $self->{path}->merge($path);
$self->{path} = ref $_[0] ? $_[0] : $self->{path}->merge($_[0]);

return $self;
}
Expand Down Expand Up @@ -128,8 +127,8 @@ sub query {
# Append hash
elsif (ref $_[0] eq 'HASH') { $q->append(%{$_[0]}) }

# Replace with string
else { $q->parse($_[0]) }
# New parameters
else { $self->{query} = ref $_[0] ? $_[0] : $q->parse($_[0]) }

return $self;
}
Expand Down Expand Up @@ -413,9 +412,10 @@ Normalized version of L</"scheme">.
=head2 query
my $query = $url->query;
$url = $url->query(replace => 'with');
$url = $url->query([merge => 'with']);
$url = $url->query({append => 'to'});
$url = $url->query(replace => 'with');
$url = $url->query('a=1&b=2');
$url = $url->query(Mojo::Parameters->new);
Query part of this URL, pairs in an array will be merged and pairs in a hash
Expand Down
8 changes: 6 additions & 2 deletions t/mojo/url.t
Expand Up @@ -77,10 +77,14 @@ is "$url", 'http://sri:foobar@example.com:8080?foo=23&bar=24&baz=25#23',
'right format';
$url->query([foo => 26, bar => undef, baz => undef]);
is "$url", 'http://sri:foobar@example.com:8080?foo=26#23', 'right format';
$url->query(Mojo::Parameters->new('a=1&b=2'));
is "$url", 'http://sri:foobar@example.com:8080?a=1&b=2#23', 'right format';
$url->query(c => 3);
is "$url", 'http://sri:foobar@example.com:8080?c=3#23', 'right format';
$url->query(Mojo::Parameters->new('a=1&b=2'));
is_deeply $url->query->to_hash, {a => 1, b => 2}, 'right structure';
is "$url", 'http://sri:foobar@example.com:8080?a=1&b=2#23', 'right format';
$url->query(Mojo::Parameters->new('%E5=%E4')->charset(undef));
is_deeply $url->query->to_hash, {"\xe5" => "\xe4"}, 'right structure';
is "$url", 'http://sri:foobar@example.com:8080?%E5=%E4#23', 'right format';

# Query string
$url = Mojo::URL->new(
Expand Down

0 comments on commit cb97c26

Please sign in to comment.