Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix a bug in Mojo::URL where invalid fragment strings could be generated
  • Loading branch information
kraih committed Jan 11, 2017
1 parent 1c5ca37 commit 777f24f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

7.18 2017-01-11
- Fixed support for relative %INC paths in Mojo::Home.
- Fixed a bug in Mojo::URL where invalid fragment strings could be generated.

7.17 2017-01-11
- Fixed Windows bugs in Mojo::File. (kmx)
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/URL.pm
Expand Up @@ -166,7 +166,7 @@ sub to_string {
# Fragment
return $url unless defined(my $fragment = $self->fragment);
return $url . '#' . url_escape encode('UTF-8', $fragment),
'^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?';
'^A-Za-z0-9\-._~!$&\'()*+,;=:@/?';
}

sub username { (shift->userinfo // '') =~ /^([^:]+)/ ? $1 : undef }
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/request.t
Expand Up @@ -2098,7 +2098,7 @@ $req->parse("HTTP/1.1\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, "/#09azAZ!\$%&\'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%9F",
is $req->url, "/#09azAZ!\$%25&\'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%9F",
'right URL';

# Abstract methods
Expand Down
20 changes: 10 additions & 10 deletions t/mojo/url.t
Expand Up @@ -26,22 +26,22 @@ is $url->path, '/x/index.html', 'right path';
is $url->query, 'monkey=biz&foo=1', 'right query';
is $url->path_query, '/x/index.html?monkey=biz&foo=1', 'right path and query';
is $url->fragment, '/!%?@3', 'right fragment';
is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%?@3',
is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%25?@3',
'right format';
$url->path('/index.xml');
is "$url", 'https://example.com:8080/index.xml?monkey=biz&foo=1#/!%?@3',
is "$url", 'https://example.com:8080/index.xml?monkey=biz&foo=1#/!%25?@3',
'right format';

# Advanced userinfo and fragment roundtrip
$url = Mojo::URL->new(
'ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=%:@/?');
is $url->scheme, 'ws', 'right scheme';
is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo';
is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username';
is $url->password, '', 'right password';
is $url->host, 'localhost', 'right host';
is $url->fragment, 'AZaz09-._~!$&\'()*+,;=%:@/?', 'right fragment';
is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=%:@/?', 'right format';
'ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=:@/?');
is $url->scheme, 'ws', 'right scheme';
is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo';
is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username';
is $url->password, '', 'right password';
is $url->host, 'localhost', 'right host';
is $url->fragment, 'AZaz09-._~!$&\'()*+,;=:@/?', 'right fragment';
is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=:@/?', 'right format';

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

0 comments on commit 777f24f

Please sign in to comment.