Strange routing behavior with some URL encoded chars

50 views
Skip to first unread message

XDF

unread,
Feb 22, 2011, 5:43:53 PM2/22/11
to Mojolicious
I noticed this odd behavior on Windows when routing URLs with some URL
encoded characters. Mojolicious version is 1.11. Is this a bug or
could you explain what is going on.

-- URLs and their results

http://localhost:3000/ -> bare root matched -> OK
http://localhost:3000/en/ -> matched root under a language -> OK
http://localhost:3000/en/this/that/ -> general match under a language -
> OK
http://localhost:3000/en/this/1234/ -> general match under a language -
> OK
http://localhost:3000/en/th%20is/ -> general match under a language ->
OK
http://localhost:3000/en/th%2Bis/ -> general match under a language ->
OK
http://localhost:3000/en/th%E4is/ -> bare root matched -> STRANGE
http://localhost:3000/en/th%FCis/ -> bare root matched -> STRANGE

-- /lib/Test.pm

package Test;
use strict;
use warnings;
use parent 'Mojolicious';
sub startup {
my $self = shift;
warn $Mojolicious::VERSION;
my $r = $self->routes;
$r->route('/')->to( cb => sub {
my $self = shift; $self->render( text => 'bare root matched' );
});
my $l = $r->route ('/:lang', lang => qr/(en|se|fi)/ );
$l->route( '/' )->to( cb => sub {
my $self = shift; $self->render( text => 'matched root under a
language' );
});
$l->route('(*path)')->to( cb => sub {
my $self = shift; $self->render( text => 'general match under a
language' );
});
}
1;

-- /script/test

#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename 'dirname';
use File::Spec;
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), 'lib';
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), '..',
'lib';
eval 'use Mojolicious::Commands';
die <<EOF if $@;
It looks like you don't have the Mojolicious Framework installed.
Please visit http://mojolicio.us for detailed installation
instructions.
EOF
$ENV{MOJO_APP} ||= 'Test';
Mojolicious::Commands->start;

-- startup at windows command line

> perl test daemon

1.11 at ../lib/Test.pm line 7.
Wed Feb 23 00:29:46 2011 info Mojo::Server::Daemon:316 [9528]:
Server listening (http://*:3000)
Server available at http://*:3000.

Sebastian Riedel

unread,
Feb 22, 2011, 5:50:20 PM2/22/11
to mojol...@googlegroups.com
my $l = $r->route ('/:lang', lang => qr/(en|se|fi)/ );

Dmitry Konstantinov

unread,
Feb 23, 2011, 6:45:25 AM2/23/11
to mojol...@googlegroups.com
it seems to be typo in documentation
i see

$r->route('/:name', name => qr/\[a-zA-Z]+/)

shuold be

$r->route('/:name', name => qr/[a-zA-Z]+/)

am i right?

2011/2/23 Sebastian Riedel <kra...@googlemail.com>

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To post to this group, send email to mojol...@googlegroups.com.
To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.



--
С уважением,
  Дмитрий

Sebastian Riedel

unread,
Feb 23, 2011, 6:50:30 AM2/23/11
to mojol...@googlegroups.com
$r->route('/:name', name => qr/\[a-zA-Z]+/)

That's indeed a typo.

XDF

unread,
Feb 23, 2011, 10:33:36 AM2/23/11
to Mojolicious

On 23 helmi, 00:50, Sebastian Riedel <kra...@googlemail.com> wrote:
> my $l = $r->route ('/:lang', lang => qr/(en|se|fi)/ );
> This regex is very wrong, you should take a look at the documentation.

Thanks! Yes, using parentheses was clearly against the documentation.
Some most obvious solutions still seem to replicate the strange
behavior -> bare root matched

my $l = $r->route ('/:lang', lang => qr/[a-z][a-z]/ );
my $l = $r->route ('/:lang', lang => qr/../ );
my $l = $r->route ('/:lang', lang => qr/[a-z]+/ );
my $l = $r->route ('/:lang', lang => qr/en/ );

Investigating further...

Sebastian Riedel

unread,
Feb 23, 2011, 12:15:11 PM2/23/11
to mojol...@googlegroups.com

> Thanks! Yes, using parentheses was clearly against the documentation.
> Some most obvious solutions still seem to replicate the strange
> behavior -> bare root matched
>
> my $l = $r->route ('/:lang', lang => qr/[a-z][a-z]/ );
> my $l = $r->route ('/:lang', lang => qr/../ );
> my $l = $r->route ('/:lang', lang => qr/[a-z]+/ );
> my $l = $r->route ('/:lang', lang => qr/en/ );
>
> Investigating further...

Building complicated regular expressions can be tricky, make sure to use "./script/myapp routes" to look at the final result.

XDF

unread,
Feb 23, 2011, 2:35:37 PM2/23/11
to Mojolicious
I have now boiled it down to this minimal example. Still no idea why
this is happening. Mojolicoius 1.11 on Windows 7 64-bit.

-- URLs and their results

http://localhost:3000/simple -> simple -> OK
http://localhost:3000/longer1234 -> longer1234 -> OK
http://localhost:3000/aaa%20bbb -> aaa bbb -> OK
http://localhost:3000/aaa%24bbb -> aaa$bbb -> OK
http://localhost:3000/aaa%3Fbbb -> aaa?bbb -> OK
http://localhost:3000/aaa%E4bbb -> This page is brand new and has not
been unboxed yet! -> STRANGE
http://localhost:3000/aaa%FCbbb -> This page is brand new and has not
been unboxed yet! -> STRANGE
http://localhost:3000/aaa%DFbbb -> This page is brand new and has not
been unboxed yet! -> STRANGE

-- /lib/Test.pm

package Test;
use strict;
use warnings;
use parent 'Mojolicious';
sub startup {
my $self = shift;
warn $Mojolicious::VERSION;
my $r = $self->routes;
$r->route ('/:capture' )->to( cb => sub {
my $self = shift; $self->render(
text => $self->stash->{capture}
);
});
}
1;

-- /script/test

#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename 'dirname';
use File::Spec;
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), 'lib';
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), '..',
'lib';
eval 'use Mojolicious::Commands';
die <<EOF if $@;
It looks like you don't have the Mojolicious Framework installed.
Please visit http://mojolicio.us for detailed installation
instructions.
EOF
$ENV{MOJO_APP} ||= 'Test';
Mojolicious::Commands->start;

-- startup at windows command line

> perl test daemon

1.11 at ../lib/Test.pm line 7.
Wed Feb 23 21:19:21 2011 info Mojo::Server::Daemon:316 [3748]: Server
listening
(http://*:3000)
Server available at http://*:3000.

-- routes

> perl test routes
1.11 at ../lib/Test.pm line 7.
/:capture capture (?-xism:^/([^\/\.]+))

XDF

unread,
Feb 23, 2011, 3:35:59 PM2/23/11
to Mojolicious

Also tested this on Debian GNU/Linux 5.0 and the behavior is the same.
So this is not related to Windows or ActivePerl.

Alister West

unread,
Feb 23, 2011, 7:30:22 PM2/23/11
to mojol...@googlegroups.com, XDF
> Also tested this on Debian GNU/Linux 5.0 and the behavior is the same.

I can confirm this behaviour on Ubuntu 10.04, perl-5.10.1, mojo-1.11
It looks like mojolicious is trying to interpolate %E in %E4 (ä) in
the capturing regex.


----- contents of 'Test' --------
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/(*capture)' => sub {
my $self = shift;
$self->render( text => $self->stash('capture'). "\n" );
};
app->start;
__DATA__
@@ not_found.html.ep
Not Found!

----------
bash> for url in /simple /aaa%3Fbbb /aaaäbbb /aaa%E4bbb; do echo GET
$url; ./Test --mode=deployment GET $url; done
GET /simple
simple
GET /aaa%3Fbbb
aaa?bbb
GET /aaaäbbb
aaaäbbb
GET /aaa%E4bbb
Use of uninitialized value in pattern match (m//) at
/home/alister/perl5/lib/perl5/Mojolicious/Routes/Pattern.pm line 121.
Use of uninitialized value in substitution (s///) at
/home/alister/perl5/lib/perl5/Mojolicious/Routes/Pattern.pm line 124.
Use of uninitialized value in substitution (s///) at
/home/alister/perl5/lib/perl5/Mojolicious/Routes/Pattern.pm line 124.
Not Found!


~~
 c|_|  alisterwest.com - mmm coffee!

Sebastian Riedel

unread,
Feb 23, 2011, 7:47:39 PM2/23/11
to mojol...@googlegroups.com

XDF

unread,
Feb 24, 2011, 2:28:48 PM2/24/11
to Mojolicious
> Should be fixed now.

Yes, works now without issues. Thank you!
Reply all
Reply to author
Forward
0 new messages