From: John Napiorkowski Date: Tue, 25 Nov 2014 18:13:04 +0000 (-0600) Subject: more unicode tests X-Git-Tag: 5.90079_001~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e5a5e80ba295da3a2f1fd8610b2f03299f9c5719 more unicode tests --- diff --git a/Changes b/Changes index f4326ce..93e194f 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,13 @@ - We no longer use Encode::is_utf8 since it doesn't work the way we think it does... This required some UTF-8 changes. If your application is UTF-8 aware I highly suggest you test this release. + - We alway do utf8 decoding on incoming URLs (before we only did so if the server + encoding was utf8. I believe this is correct as per the w3c spec, but please + correct if incorrect :) + - Debug output now shows utf8 characters if those are incoming via Args or as + path or pathparts in your actions. query and body parameter keys are now also + subject to utf8 decoding (or as specificed via the encoding configuration value). + - lots of UTF8 changes. Again we think this is now more correct but please test. 5.90074 - 2014-10-01 - Specify Carp minimum version to avoid pointless test fails (valy++) diff --git a/t/utf_incoming.t b/t/utf_incoming.t index 4a697cc..096ba69 100644 --- a/t/utf_incoming.t +++ b/t/utf_incoming.t @@ -25,12 +25,43 @@ use HTTP::Request::Common; $c->response->body("

This is path-hat action ^

"); } + sub uri_for :Path('uri_for') { + my ($self, $c) = @_; + $c->response->content_type('text/html'); + $c->response->body("${\$c->uri_for($c->controller('Root')->action_for('argend'), ['♥'], '♥', {'♥'=>'♥♥'})}"); + } + + sub heart_with_arg :Path('a♥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + $c->response->body("

This is path-heart-arg action $arg

"); + Test::More::is $c->req->args->[0], '♥'; + } + sub base :Chained('/') CaptureArgs(0) { } sub link :Chained('base') PathPart('♥') Args(0) { my ($self, $c) = @_; $c->response->content_type('text/html'); $c->response->body("

This is base-link action ♥

"); } + sub arg :Chained('base') PathPart('♥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + $c->response->body("

This is base-link action ♥ $arg

"); + } + sub capture :Chained('base') PathPart('♥') CaptureArgs(1) { + my ($self, $c, $arg) = @_; + $c->stash(capture=>$arg); + } + sub argend :Chained('capture') PathPart('♥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + + Test::More::is $c->req->args->[0], '♥'; + Test::More::is $c->req->captures->[0], '♥'; + + $c->response->body("

This is base-link action ♥ ${\$c->req->args->[0]}

"); + } package MyApp; use Catalyst; @@ -54,6 +85,14 @@ use Encode 2.21 'decode_utf8', 'encode_utf8'; } { + my $res = request "/root/a♥/♥"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), '

This is path-heart-arg action ♥

', 'correct body'; + is $res->content_length, 40, 'correct length'; +} + +{ my $res = request "/root/^"; is $res->code, 200, 'OK'; @@ -79,16 +118,60 @@ use Encode 2.21 'decode_utf8', 'encode_utf8'; is $c->req->query_parameters->{'♥'}[0], '♥'; is $c->req->body_parameters->{'♥'}[0], '♥'; is $c->req->parameters->{'♥'}[0], '♥'; - is $c->req->parameters->{a}, 1; is $c->req->body_parameters->{a}, 1; +} +{ + my ($res, $c) = ctx_request GET "/base/♥?♥♥♥"; + is $res->code, 200, 'OK'; + is decode_utf8($res->content), '

This is base-link action ♥

', 'correct body'; + is $res->content_length, 35, 'correct length'; + is $c->req->query_keywords, '♥♥♥'; } -## tests for args and captureargs (chained and otherise) -## warn $c->req->uri; (seemsto be pre encodinged and all -## test what uri_for looks like in responses +{ + my $res = request "/base/♥/♥"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), '

This is base-link action ♥ ♥

', 'correct body'; + is $res->content_length, 39, 'correct length'; +} +{ + my $res = request "/base/♥/♥/♥/♥"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), '

This is base-link action ♥ ♥

', 'correct body'; + is $res->content_length, 39, 'correct length'; +} + +{ + my ($res, $c) = ctx_request POST "/base/♥/♥/♥/♥?♥=♥♥", [a=>1, b=>'2', '♥'=>'♥♥']; + + ## Make sure that the urls we generate work the same + my $uri_for = $c->uri_for($c->controller('Root')->action_for('argend'), ['♥'], '♥', {'♥'=>'♥♥'}); + my $uri = $c->req->uri; + + is "$uri", "$uri_for"; + + { + my ($res, $c) = ctx_request POST "$uri_for", [a=>1, b=>'2', '♥'=>'♥♥']; + is $c->req->query_parameters->{'♥'}, '♥♥'; + is $c->req->body_parameters->{'♥'}, '♥♥'; + is $c->req->parameters->{'♥'}[0], '♥♥'; #combined with query and body + } +} + +{ + my ($res, $c) = ctx_request "/root/uri_for"; + my $url = $c->uri_for($c->controller('Root')->action_for('argend'), ['♥'], '♥', {'♥'=>'♥♥'}); + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), "$url", 'correct body'; #should do nothing + is $res->content, "$url", 'correct body'; + is $res->content_length, 90, 'correct length'; +} done_testing;