Skip to content

Commit

Permalink
fixed small escaping bug in Mojo::URL
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 5, 2012
1 parent 275056c commit 058b5fb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -14,6 +14,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Fixed empty frame handling in Mojo::Transaction::WebSocket.
- Fixed small rendering bug in Mojolicious::Plugin::PODRenderer.
- Fixed small code generation bug in Mojolicious::Plugin::I18N.
- Fixed small escaping bug in Mojo::URL.

2.92 2012-04-30
- Added commands attribute to Mojolicious.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Parameters.pm
Expand Up @@ -171,7 +171,7 @@ sub to_string {
my $charset = $self->charset;
if (defined(my $string = $self->{string})) {
$string = encode $charset, $string if $charset;
return url_escape $string, "^$Mojo::URL::UNRESERVED\\&\\;\\=\\+\\%";
return url_escape $string, "^$Mojo::URL::UNRESERVED\&\;\=\+\%";
}

# Build pairs
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Path.pm
Expand Up @@ -63,9 +63,8 @@ sub contains {

sub parse {
my ($self, $path) = @_;
$path //= '';

$path = url_unescape $path;
$path = url_unescape $path // '';
utf8::decode $path;
$path =~ s|^/|| ? $self->leading_slash(1) : $self->leading_slash(undef);
$path =~ s|/$|| ? $self->trailing_slash(1) : $self->trailing_slash(undef);
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/URL.pm
Expand Up @@ -14,8 +14,7 @@ has base => sub { Mojo::URL->new };

# Characters (RFC 3986)
our $UNRESERVED = 'A-Za-z0-9\-\.\_\~';
our $SUBDELIM = '!\$\&\'\(\)\*\+\,\;\=';
my $PCHAR = "$UNRESERVED$SUBDELIM\%\:\@";
our $SUBDELIM = '\!\$\&\'\(\)\*\+\,\;\=';

# "Homer, it's easy to criticize.
# Fun, too."
Expand Down Expand Up @@ -251,7 +250,7 @@ sub to_string {

# Fragment
if (my $fragment = $self->fragment) {
$url .= '#' . url_escape $fragment, "^$PCHAR\/\?";
$url .= '#' . url_escape $fragment, "^$UNRESERVED$SUBDELIM\%\:\@\/\?";
}

return $url;
Expand Down
8 changes: 4 additions & 4 deletions t/mojo/parameters.t
Expand Up @@ -152,10 +152,10 @@ is_deeply $p->to_hash,

# Unicode
$p = Mojo::Parameters->new;
$p->parse('input=say%20%22%C2%AB%22;');
is $p->params->[1], 'say "«"', 'right value';
is $p->param('input'), 'say "«"', 'right value';
is "$p", 'input=say+%22%C2%AB%22', 'right result';
$p->parse('input=say%20%22%C2%AB~%22;');
is $p->params->[1], 'say "«~"', 'right value';
is $p->param('input'), 'say "«~"', 'right value';
is "$p", 'input=say+%22%C2%AB~%22', 'right result';

# Reparse
$p = Mojo::Parameters->new('foo=bar&baz=23');
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/path.t
Expand Up @@ -29,12 +29,12 @@ is $path->parts->[2], 'bar', 'right part';
is $path->parts->[3], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok !$path->trailing_slash, 'no trailing slash';
is $path->parse('/foo/%E2%99%A5/bar')->to_string, '/foo/%E2%99%A5/bar',
is $path->parse('/foo/%E2%99%A5/~b@a:r+')->to_string, '/foo/%E2%99%A5/~b@a:r+',
'right path';
is $path->parts->[0], 'foo', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], 'bar', 'right part';
is $path->parts->[3], undef, 'no part';
is $path->parts->[0], 'foo', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], '~b@a:r+', 'right part';
is $path->parts->[3], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok !$path->trailing_slash, 'no trailing slash';

Expand Down
9 changes: 5 additions & 4 deletions t/mojo/url.t
Expand Up @@ -16,20 +16,21 @@ is "$url", 'http://kraih.com', 'right format';

# Advanced
$url = Mojo::URL->new(
'http://sri:foobar@kraih.com:8080/test/index.html?monkey=biz&foo=1#23');
'http://sri:foobar@kraih.com:8080/test/index.html?monkey=biz&foo=1#/!%?@3');
ok $url->is_abs, 'is absolute';
is $url->scheme, 'http', 'right scheme';
is $url->userinfo, 'sri:foobar', 'right userinfo';
is $url->host, 'kraih.com', 'right host';
is $url->port, '8080', 'right port';
is $url->path, '/test/index.html', 'right path';
is $url->query, 'monkey=biz&foo=1', 'right query';
is $url->fragment, '23', 'right fragment';
is $url->fragment, '/!%?@3', 'right fragment';
is "$url",
'http://sri:foobar@kraih.com:8080/test/index.html?monkey=biz&foo=1#23',
'http://sri:foobar@kraih.com:8080/test/index.html?monkey=biz&foo=1#/!%?@3',
'right format';
$url->path('/index.xml');
is "$url", 'http://sri:foobar@kraih.com:8080/index.xml?monkey=biz&foo=1#23',
is "$url",
'http://sri:foobar@kraih.com:8080/index.xml?monkey=biz&foo=1#/!%?@3',
'right format';

# Parameters
Expand Down

0 comments on commit 058b5fb

Please sign in to comment.