[Catalyst-commits] r11798 - in
Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2:
. lib t/aggregate t/lib/TestApp/Controller/Action
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Thu Nov 12 00:22:06 GMT 2009
Author: t0m
Date: 2009-11-12 00:22:06 +0000 (Thu, 12 Nov 2009)
New Revision: 11798
Modified:
Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/Makefile.PL
Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/aggregate/live_component_controller_action_chained.t
Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/lib/TestApp/Controller/Action/Chained.pm
Log:
Tests, fix args as well as captureargs and be less violent - only encode /
Modified: Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/Makefile.PL 2009-11-11 10:58:24 UTC (rev 11797)
+++ Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/Makefile.PL 2009-11-12 00:22:06 UTC (rev 11798)
@@ -52,6 +52,7 @@
test_requires 'Class::Data::Inheritable';
test_requires 'Test::Exception';
+test_requires 'Test::More' => '0.88';
# aggregate tests if AGGREGATE_TESTS is set and a recent Test::Aggregate and a Test::Simple it works with is available
if ($ENV{AGGREGATE_TESTS} && can_use('Test::Simple', '0.88') && can_use('Test::Aggregate', '0.35_05')) {
Modified: Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/lib/Catalyst.pm 2009-11-11 10:58:24 UTC (rev 11797)
+++ Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/lib/Catalyst.pm 2009-11-12 00:22:06 UTC (rev 11798)
@@ -1247,7 +1247,7 @@
}
if ( blessed($path) ) { # action object
- my $captures = [ map { URI::Escape::uri_escape($_) }
+ my $captures = [ map { s|/|%2F|; $_; }
( scalar @args && ref $args[0] eq 'ARRAY'
? @{ shift(@args) }
: ()) ];
@@ -1268,6 +1268,7 @@
carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
+ s|/|%2F| for @args;
unshift(@args, $path);
Modified: Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/aggregate/live_component_controller_action_chained.t
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/aggregate/live_component_controller_action_chained.t 2009-11-11 10:58:24 UTC (rev 11797)
+++ Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/aggregate/live_component_controller_action_chained.t 2009-11-12 00:22:06 UTC (rev 11798)
@@ -10,7 +10,7 @@
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-use Test::More tests => 148*$iters;
+use Test::More;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
@@ -1018,5 +1018,27 @@
'request with URI-encoded arg' );
like( $content, qr{foo/bar;\z}, 'args decoded' );
}
+
+ # Test round tripping, specifically the / character %2F in uri_for:
+ # not being able to feed it back action + captureargs and args into uri for and result in the original
+ # request uri is a major piece of suck ;)
+ # FIXME - what about people who have code to hack around this and manually uri encode args and captures
+ # themselves, erk!
+ foreach my $thing (
+ ['foo', 'bar'],
+ ['foo%2Fbar', 'baz'],
+ ['foo', 'bar%2Fbaz'],
+ ['foo%2Fbar', 'baz%2Fquux'],
+ ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz' => 'quux%2Ffrood'}],
+ ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz%2Ffnoo' => 'quux%2Ffrood'}],
+ ) {
+ my $uri = 'http://localhost/chained/roundtrip_urifor/' . $thing->[0] . '/' . $thing->[1];
+ $uri .= '?' . join('&', map { $_ .'='. $thing->[2]->{$_}} sort keys %{$thing->[2]}) if $thing->[2];
+ ok( my $content =
+ get($uri),
+ 'request ' . $uri . ' ok');
+ is( $content, $uri, 'uri can round trip through uri_for' );
+ }
}
+done_testing;
Modified: Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/lib/TestApp/Controller/Action/Chained.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/lib/TestApp/Controller/Action/Chained.pm 2009-11-11 10:58:24 UTC (rev 11797)
+++ Catalyst-Runtime/5.80/branches/uri_encode_captures_andor_args_take2/t/lib/TestApp/Controller/Action/Chained.pm 2009-11-12 00:22:06 UTC (rev 11798)
@@ -204,6 +204,13 @@
$c->req->args([ map { decode_entities($_) } @{ $c->req->args }]);
}
+sub roundtrip_urifor : Chained('/') PathPart('chained/roundtrip_urifor') CaptureArgs(1) {}
+sub roundtrip_urifor_end : Chained('roundtrip_urifor') PathPart('') Args(1) {
+ my ($self, $c) = @_;
+ # This should round-trip, always - i.e. the uri you put in should come back out.
+ $c->res->body($c->uri_for($c->action, $c->req->captures, @{$c->req->args}, $c->req->parameters));
+ $c->stash->{no_end} = 1;
+}
sub end :Private {
my ($self, $c) = @_;
More information about the Catalyst-commits
mailing list