Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
parse URLs a little faster
  • Loading branch information
kraih committed Dec 30, 2014
1 parent 1679faf commit b736b64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.71 2014-12-29
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.
- Fixed fragment and userinfo normalization bugs in Mojo::URL.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM.pm
Expand Up @@ -448,8 +448,8 @@ Mojo::DOM - Minimalistic HTML/XML DOM parser with CSS selectors
=head1 DESCRIPTION
L<Mojo::DOM> is a minimalistic and relaxed HTML/XML DOM parser with CSS
selector support. It will even try to interpret broken XML, so you should not
use it for validation.
selector support. It will even try to interpret broken HTML and XML, so you
should not use it for validation.
=head1 CASE SENSITIVITY
Expand Down
19 changes: 12 additions & 7 deletions lib/Mojo/URL.pm
Expand Up @@ -15,7 +15,7 @@ sub authority {

# New authority
if (@_) {
return $self unless defined(my $authority = shift);
my $authority = shift;

# Userinfo
$self->userinfo(_decode(url_unescape $1)) if $authority =~ s/^([^\@]+)\@//;
Expand All @@ -31,8 +31,7 @@ sub authority {
# Build authority
return undef unless defined(my $authority = $self->host_port);
return $authority unless defined(my $info = $self->userinfo);
$info = url_escape encode('UTF-8', $info), '^A-Za-z0-9\-._~!$&\'()*+,;=:';
return "$info\@$authority";
return _encode($info, '^A-Za-z0-9\-._~!$&\'()*+,;=:') . '@' . $authority;
}

sub host_port {
Expand Down Expand Up @@ -77,8 +76,13 @@ sub parse {

# Official regex from RFC 3986
$url =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!;
$self->scheme($2)->authority($4)->path($5)->query($7);
return defined $9 ? $self->fragment(_decode(url_unescape $9)) : $self;
$self->scheme($2) if defined $2;
$self->authority($4) if defined $4;
$self->path($5) if defined $5;
$self->query($7) if defined $7;
$self->fragment(_decode(url_unescape $9)) if defined $9;

return $self;
}

sub path {
Expand Down Expand Up @@ -182,12 +186,13 @@ sub to_string {

# Fragment
return $url unless defined(my $fragment = $self->fragment);
return $url . '#' . url_escape encode('UTF-8', $fragment),
'^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?';
return $url . '#' . _encode($fragment, '^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?');
}

sub _decode { decode('UTF-8', $_[0]) // $_[0] }

sub _encode { url_escape encode('UTF-8', $_[0]), $_[1] }

1;

=encoding utf8
Expand Down

0 comments on commit b736b64

Please sign in to comment.