Skip to content

Commit

Permalink
fixed ";" handling in Mojo::Parameters to be compliant with the HTML …
Browse files Browse the repository at this point in the history
…Living Standard
  • Loading branch information
kraih committed Feb 7, 2014
1 parent 8ef279d commit 2d1cf0e
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

4.78 2014-02-07
- Fixed ";" handling in Mojo::Parameters to be compliant with the HTML
Living Standard.

4.77 2014-02-06
- Deprecated Mojo::DOM::text_after and Mojo::DOM::text_before in favor of
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Exception.pm
Expand Up @@ -94,7 +94,7 @@ sub _detect {
}

# More context
$self->_context($trace[0][1], [map { [split /\n/] } @$files]) if $files;
$self->_context($trace[0][1], [map { [split "\n"] } @$files]) if $files;

return $self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Home.pm
Expand Up @@ -33,7 +33,7 @@ sub detect {
}

# FindBin fallback
return $self->parts([split /\//, $FindBin::Bin]);
return $self->parts([split '/', $FindBin::Bin]);
}

sub lib_dir {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -305,7 +305,7 @@ sub _exception {
my $context = 'Malformed JSON: ' . shift;
if (m/\G\z/gc) { $context .= ' before end of data' }
else {
my @lines = split /\n/, substr($_, 0, pos);
my @lines = split "\n", substr($_, 0, pos);
$context .= ' at line ' . @lines . ', offset ' . length(pop @lines || '');
}

Expand Down
27 changes: 14 additions & 13 deletions lib/Mojo/Parameters.pm
Expand Up @@ -81,9 +81,8 @@ sub params {
my $params = $self->{params} = [];
return $params unless length $str;

# W3C suggests to also accept ";" as a separator
my $charset = $self->charset;
for my $pair (split /&|;/, $str) {
for my $pair (split '&', $str) {
next unless $pair =~ /^([^=]+)(?:=(.*))?$/;
my $name = $1;
my $value = $2 // '';
Expand Down Expand Up @@ -201,7 +200,9 @@ Mojo::Parameters - Parameters
=head1 DESCRIPTION
L<Mojo::Parameters> is a container for form parameters used by L<Mojo::URL>.
L<Mojo::Parameters> is a container for form parameters used by L<Mojo::URL>
and based on L<RFC 3986|http://tools.ietf.org/html/rfc3986> as well as the
L<HTML Living Standard|http://www.whatwg.org/html>.
=head1 ATTRIBUTES
Expand All @@ -224,9 +225,9 @@ following new ones.
=head2 append
$params = $params->append(foo => 'ba;r');
$params = $params->append(foo => ['ba;r', 'b;az']);
$params = $params->append(foo => ['ba;r', 'b;az'], bar => 23);
$params = $params->append(foo => 'ba&r');
$params = $params->append(foo => ['ba&r', 'baz']);
$params = $params->append(foo => ['bar', 'baz'], bar => 23);
Append parameters. Note that this method will normalize the parameters.
Expand All @@ -247,7 +248,7 @@ Clone parameters.
=head2 merge
$params = $params->merge(Mojo::Parameters->new(foo => 'b;ar', baz => 23));
$params = $params->merge(Mojo::Parameters->new(foo => 'b&ar', baz => 23));
Merge L<Mojo::Parameters> objects. Note that this method will normalize the
parameters.
Expand All @@ -256,9 +257,9 @@ parameters.
my $params = Mojo::Parameters->new;
my $params = Mojo::Parameters->new('foo=b%3Bar&baz=23');
my $params = Mojo::Parameters->new(foo => 'b;ar');
my $params = Mojo::Parameters->new(foo => ['ba;r', 'b;az']);
my $params = Mojo::Parameters->new(foo => ['ba;r', 'b;az'], bar => 23);
my $params = Mojo::Parameters->new(foo => 'b&ar');
my $params = Mojo::Parameters->new(foo => ['ba&r', 'baz']);
my $params = Mojo::Parameters->new(foo => ['bar', 'baz'], bar => 23);
Construct a new L<Mojo::Parameters> object and L</"parse"> parameters if
necessary.
Expand All @@ -268,8 +269,8 @@ necessary.
my @names = $params->param;
my $foo = $params->param('foo');
my @foo = $params->param('foo');
my $foo = $params->param(foo => 'ba;r');
my @foo = $params->param(foo => qw(ba;r ba;z));
my $foo = $params->param(foo => 'ba&r');
my @foo = $params->param(foo => qw(ba&r baz));
Check and replace parameter value. Be aware that if you request a parameter by
name in scalar context, you will receive only the I<first> value for that
Expand All @@ -280,7 +281,7 @@ normalize the parameters.
=head2 params
my $array = $params->params;
$params = $params->params([foo => 'b;ar', baz => 23]);
$params = $params->params([foo => 'b&ar', baz => 23]);
Parsed parameters. Note that this method will normalize the parameters.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Path.pm
Expand Up @@ -152,7 +152,8 @@ Mojo::Path - Path
=head1 DESCRIPTION
L<Mojo::Path> is a container for paths used by L<Mojo::URL>.
L<Mojo::Path> is a container for paths used by L<Mojo::URL> and based on
L<RFC 3986|http://tools.ietf.org/html/rfc3986>.
=head1 ATTRIBUTES
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/Daemon.pm
Expand Up @@ -13,7 +13,7 @@ has acceptors => sub { [] };
has [qw(backlog group silent user)];
has inactivity_timeout => sub { $ENV{MOJO_INACTIVITY_TIMEOUT} // 15 };
has ioloop => sub { Mojo::IOLoop->singleton };
has listen => sub { [split /,/, $ENV{MOJO_LISTEN} || 'http://*:3000'] };
has listen => sub { [split ',', $ENV{MOJO_LISTEN} || 'http://*:3000'] };
has max_clients => 1000;
has max_requests => 25;

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -153,7 +153,7 @@ sub parse {
# Split lines
my $state = 'text';
my ($trimming, @capture_token);
for my $line (split /\n/, $template) {
for my $line (split "\n", $template) {
$trimming = 0 if $state eq 'text';

# Turn Perl line into mixed line
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent/Proxy.pm
Expand Up @@ -7,7 +7,7 @@ sub detect {
my $self = shift;
$self->http($ENV{HTTP_PROXY} || $ENV{http_proxy});
$self->https($ENV{HTTPS_PROXY} || $ENV{https_proxy});
return $self->not([split /,/, $ENV{NO_PROXY} || $ENV{no_proxy} || '']);
return $self->not([split ',', $ENV{NO_PROXY} || $ENV{no_proxy} || '']);
}

sub inject {
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojo/Util.pm
Expand Up @@ -65,8 +65,8 @@ sub camelize {

# CamelCase words
return join '::', map {
join '', map { ucfirst lc } split /_/, $_
} split /-/, $str;
join '', map { ucfirst lc } split '_', $_
} split '-', $str;
}

sub class_to_file {
Expand All @@ -84,7 +84,7 @@ sub decamelize {
# Module parts
my @parts;
for my $part (split /::/, $str) {
for my $part (split '::', $str) {
# snake_case words
my @words;
Expand Down Expand Up @@ -152,7 +152,7 @@ sub punycode_decode {
my @output;
# Consume all code points before the last delimiter
push @output, split //, $1 if $input =~ s/(.*)\x2d//s;
push @output, split '', $1 if $input =~ s/(.*)\x2d//s;
while (length $input) {
my $oldi = $i;
Expand Down Expand Up @@ -189,7 +189,7 @@ sub punycode_encode {
# Extract basic code points
my $len = length $output;
my @input = map {ord} split //, $output;
my @input = map {ord} split '', $output;
my @chars = sort grep { $_ >= PC_INITIAL_N } @input;
$output =~ s/[^\x00-\x7f]+//gs;
my $h = my $b = length $output;
Expand Down Expand Up @@ -320,7 +320,7 @@ sub trim {

sub unindent {
my $str = shift;
my $min = min map { m/^([ \t]*)/; length $1 || () } split /\n/, $str;
my $min = min map { m/^([ \t]*)/; length $1 || () } split "\n", $str;
$str =~ s/^[ \t]{0,$min}//gm if $min;
return $str;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Command.pm
Expand Up @@ -57,9 +57,9 @@ sub help {
exit 0;
}

sub rel_dir { catdir(getcwd(), split /\//, pop) }
sub rel_dir { catdir(getcwd(), split '/', pop) }

sub rel_file { catfile(getcwd(), split /\//, pop) }
sub rel_file { catfile(getcwd(), split '/', pop) }

sub render_data {
my ($self, $name) = (shift, shift);
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -138,7 +138,7 @@ sub template_for {
# Normal default template
my $stash = $c->stash;
my ($controller, $action) = @$stash{qw(controller action)};
return join '/', split(/-/, decamelize($controller)), $action
return join '/', split('-', decamelize($controller)), $action
if $controller && $action;

# Try the route name if we don't have controller and action
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Types.pm
Expand Up @@ -39,7 +39,7 @@ sub detect {
my %types;
/^\s*([^,; ]+)(?:\s*\;\s*q\s*=\s*(\d+(?:\.\d+)?))?\s*$/i
and $types{lc $1} = $2 // 1
for split /,/, $accept // '';
for split ',', $accept // '';
my @detected = sort { $types{$b} <=> $types{$a} } sort keys %types;
return [] if !$prioritize && @detected > 1;

Expand Down
19 changes: 8 additions & 11 deletions t/mojo/parameters.t
Expand Up @@ -39,11 +39,8 @@ is_deeply [$params->param('foo')], ['bar'], 'right structure';
$params->param(foo => qw(baz yada));
is_deeply [$params->param('foo')], [qw(baz yada)], 'right structure';

# Parse with ";" separator
$params->parse('q=1;w=2;e=3;e=4;r=6;t=7');
is $params->to_string, 'q=1;w=2;e=3;e=4;r=6;t=7', 'right format';

# Remove
$params->parse('q=1&w=2&e=3&e=4&r=6&t=7');
is $params->remove('r')->to_string, 'q=1&w=2&e=3&e=4&t=7', 'right format';
$params->remove('e');
is $params->to_string, 'q=1&w=2&t=7', 'right format';
Expand Down Expand Up @@ -76,10 +73,10 @@ is $params->to_string, 'foo=0', 'right format';
# Semicolon
$params = Mojo::Parameters->new('foo=bar;baz');
is $params->to_string, 'foo=bar;baz', 'right format';
is_deeply $params->params, [foo => 'bar', baz => ''], 'right structure';
is_deeply $params->to_hash, {foo => 'bar', baz => ''}, 'right structure';
is $params->to_string, 'foo=bar&baz=', 'right format';
$params = Mojo::Parameters->new('foo=bar%3Bbaz');
is_deeply $params->params, [foo => 'bar;baz'], 'right structure';
is_deeply $params->to_hash, {foo => 'bar;baz'}, 'right structure';
is $params->to_string, 'foo=bar%3Bbaz', 'right format';
$params = Mojo::Parameters->new($params->to_string);
is_deeply $params->params, [foo => 'bar;baz'], 'right structure';
is_deeply $params->to_hash, {foo => 'bar;baz'}, 'right structure';
is $params->to_string, 'foo=bar%3Bbaz', 'right format';
Expand Down Expand Up @@ -146,9 +143,9 @@ is_deeply [$params->param('foo')], [qw(ba;r b;az)], 'right values';
# Unicode
$params = Mojo::Parameters->new;
$params->parse('input=say%20%22%C2%AB~%22;');
is_deeply $params->params, ['input', 'say "«~"'], 'right structure';
is $params->param('input'), 'say "«~"', 'right value';
is "$params", 'input=say+%22%C2%AB~%22', 'right result';
is_deeply $params->params, ['input', 'say "«~";'], 'right structure';
is $params->param('input'), 'say "«~";', 'right value';
is "$params", 'input=say+%22%C2%AB~%22%3B', 'right result';
$params = Mojo::Parameters->new('♥=☃');
is_deeply $params->params, ['', ''], 'right structure';
is $params->param(''), '', 'right value';
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/url.t
Expand Up @@ -91,11 +91,11 @@ is $url->host, 'example.com', 'right host';
is $url->port, '8080', 'right port';
is $url->path, '', 'no path';
is $url->query, '_monkeybiz%3B&_monkey;23', 'right query';
is_deeply $url->query->params, ['_monkeybiz;', '', '_monkey', '', 23, ''],
is_deeply $url->query->params, ['_monkeybiz;', '', '_monkey;23', ''],
'right structure';
is $url->query, '_monkeybiz%3B=&_monkey=&23=', 'right query';
is $url->query, '_monkeybiz%3B=&_monkey%3B23=', 'right query';
is $url->fragment, '23', 'right fragment';
is "$url", 'wss://sri:foobar@example.com:8080?_monkeybiz%3B=&_monkey=&23=#23',
is "$url", 'wss://sri:foobar@example.com:8080?_monkeybiz%3B=&_monkey%3B23=#23',
'right format';
$url = Mojo::URL->new('https://example.com/0?0#0');
ok $url->is_abs, 'is absolute';
Expand Down

0 comments on commit 2d1cf0e

Please sign in to comment.