Skip to content

Commit

Permalink
test Unicode prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 3, 2014
1 parent 6387b6b commit 5a9a889
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -236,7 +236,7 @@ but content will not be sent with the response even if it is present.
IRIs are handled transparently, that means paths are guaranteed to be
unescaped and decoded from bytes to characters.

# GET /☃ (unicode snowman) -> {controller => 'foo', action => 'snowman'}
# GET /☃ (Unicode snowman) -> {controller => 'foo', action => 'snowman'}
$r->get('/☃')->to(controller => 'foo', action => 'snowman');

=head2 Stash
Expand Down
6 changes: 3 additions & 3 deletions t/mojolicious/embedded_app.t
Expand Up @@ -64,14 +64,14 @@ $t->get_ok('/x/1/index.html')->status_is(200)
# External app with different prefix
$t->get_ok('/x/1/test')->status_is(200)->content_is('works%21');

# External app with unicode prefix
# External app with Unicode prefix
$t->get_ok('/x/♥')->status_is(200)->content_is('too%21');

# Static file from external app with unicode prefix
# Static file from external app with Unicode prefix
$t->get_ok('/x/♥/index.html')->status_is(200)
->content_is("External static file!\n");

# External app with unicode prefix again
# External app with Unicode prefix again
$t->get_ok('/x/♥/test')->status_is(200)->content_is('works%21');

# External app with domain
Expand Down
49 changes: 25 additions & 24 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -202,13 +202,7 @@ $t->get_ok('/x/1/template/menubar')->status_is(200)
# Missing template from myapp.pl
$t->get_ok('/x/1/template/does_not_exist')->status_is(404);

# Embedded WebSocket
$t->websocket_ok('/x/1/url_for')->send_ok('ws_test')
->message_ok->message_like(qr!^ws://localhost:\d+/x/1/url_for$!)
->send_ok('index')->message_ok->message_like(qr!^http://localhost:\d+/x/1$!)
->finish_ok;

# Template from myapp.pl with unicode prefix
# Template from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/')->status_is(200)->content_is(<<'EOF');
myapp
works ♥!Insecure!Insecure!
Expand All @@ -220,26 +214,26 @@ too!works!!!Mojolicious::Plugin::Config::Sandbox
</form>
EOF

# Static file from myapp.pl with unicode prefix
# Static file from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/index.html')->status_is(200)
->content_is("External static file!\n");

# Echo from myapp.pl with unicode prefix
# Echo from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/echo')->status_is(200)->content_is('echo: works 2!');

# Stream from myapp.pl with unicode prefix
# Stream from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/stream')->status_is(200)->content_is('hello!');

# URL from myapp.pl with unicode prefix
# URL from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/url/☃')->status_is(200)
->content_is(
'/x/%E2%99%A5/url/%E2%98%83.json -> /x/%E2%99%A5/%E2%98%83/stream!');

# Route to template from myapp.pl with unicode prefix
# Route to template from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/template/menubar')->status_is(200)
->content_is("myapp\nworks ♥!Insecure!Insecure!\n");

# Missing template from myapp.pl with unicode prefix
# Missing template from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/template/does_not_exist')->status_is(404);

# A little bit of everything from myapp2.pl
Expand All @@ -259,17 +253,17 @@ $t->get_ok('/y/1/cached?cache=fail')->status_is(200)->content_is('foo');
# 404 from myapp2.pl
$t->get_ok('/y/1/2')->status_is(404);

# myapp2.pl with unicode prefix
# myapp2.pl with Unicode prefix
$t->get_ok('/y/♥')->status_is(200)
->content_is("myapp2\nworks 3!\nInsecure too!");

# Caching helper from myapp2.pl with unicode prefix
# Caching helper from myapp2.pl with Unicode prefix
$t->get_ok('/y/♥/cached?cache=bar')->status_is(200)->content_is('bar');

# Caching helper with cached value from myapp2.pl with unicode prefix
# Caching helper with cached value from myapp2.pl with Unicode prefix
$t->get_ok('/y/♥/cached?cache=fail')->status_is(200)->content_is('bar');

# 404 from myapp2.pl with unicode prefix
# 404 from myapp2.pl with Unicode prefix
$t->get_ok('/y/♥/2')->status_is(404);

# main
Expand Down Expand Up @@ -334,7 +328,7 @@ $t->get_ok('/host' => {Host => 'www.example.com'})->status_is(200)
$t->get_ok('/host' => {Host => 'foo.bar.example.com'})->status_is(200)
->header_is('X-Message' => 'it works!')->content_is('foo.bar.example.com');

# Template from myapp.pl with wildcard domain and unicode prefix
# Template from myapp.pl with wildcard domain and Unicode prefix
$t->get_ok('/♥/123/' => {Host => 'foo-bar.de'})->status_is(200)
->content_is(<<'EOF');
myapp
Expand All @@ -347,27 +341,27 @@ too!works!!!Mojolicious::Plugin::Config::Sandbox
</form>
EOF

# Host from myapp.pl with wildcard domain and unicode prefix
# Host from myapp.pl with wildcard domain and Unicode prefix
$t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'})->status_is(200)
->header_is('X-Message' => 'it works!')->content_is('foo-bar.de');

# Echo from myapp.pl with wildcard domain and unicode prefix
# Echo from myapp.pl with wildcard domain and Unicode prefix
$t->get_ok('/♥/123/echo' => {Host => 'foo-bar.de'})->status_is(200)
->content_is('echo: works 3!');

# Host from myapp.pl with wildcard domain and unicode prefix again
# Host from myapp.pl with wildcard domain and Unicode prefix again
$t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'})->status_is(200)
->header_is('X-Message' => 'it works!')->content_is('www.foo-bar.de');

# Host from myapp.pl with wildcard domain and unicode prefix again
# Host from myapp.pl with wildcard domain and Unicode prefix again
$t->get_ok('/♥/123/echo' => {Host => 'www.foo-bar.de'})->status_is(200)
->content_is('echo: works 3!');

# Text from myapp.pl with wildcard domain and unicode prefix
# Text from myapp.pl with wildcard domain and Unicode prefix
$t->get_ok('/♥/123/one' => {Host => 'www.foo-bar.de'})->status_is(200)
->content_is('One');

# Another text from myapp.pl with wildcard domain and unicode prefix
# Another text from myapp.pl with wildcard domain and Unicode prefix
$t->get_ok('/♥/123/one/two' => {Host => 'www.foo-bar.de'})->status_is(200)
->content_is('Two');

Expand All @@ -377,6 +371,13 @@ $t->get_ok('/' => {Host => 'mojoliciousxorg'})->status_is(404);
# Another invalid domain
$t->get_ok('/' => {Host => 'www.kraihxcom'})->status_is(404);

# Embedded WebSocket
$t->websocket_ok('/x/♥/url_for')->send_ok('ws_test')
->message_ok->message_like(qr!^ws://localhost:\d+/x/%E2%99%A5/url_for$!)
->send_ok('index')
->message_ok->message_like(qr!^http://localhost:\d+/x/%E2%99%A5$!)
->finish_ok;

done_testing();

__DATA__
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -526,7 +526,7 @@ $t->get_ok('/alternatives/☃')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_is('/alternatives/%E2%98%83');

# Different unicode alternative
# Different Unicode alternative
$t->get_ok('/alternatives/♥')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_is('/alternatives/%E2%99%A5');
Expand Down

0 comments on commit 5a9a889

Please sign in to comment.