Merge 'trunk' into 'uri_encode_captures_andor_args_take2'
Tomas Doran [Thu, 12 Nov 2009 23:43:17 +0000 (23:43 +0000)]
r11670@t0mlaptop (orig r11635):  t0m | 2009-10-19 18:02:59 +0100
Remove warnings from duplicate action declerations
r11675@t0mlaptop (orig r11640):  poisonbit | 2009-10-20 21:12:46 +0100
Example added to #Actions_in_your_application_class

r11676@t0mlaptop (orig r11641):  poisonbit | 2009-10-20 21:32:41 +0100
Formating (a lost space and line break)

r11677@t0mlaptop (orig r11642):  poisonbit | 2009-10-20 21:34:45 +0100
More regresion from 11640, correcting parentheses and endpoint.

r11678@t0mlaptop (orig r11643):  poisonbit | 2009-10-20 22:08:47 +0100
Change in actions inside roles.
http://bobtfish.livejournal.com/264317.html

r11679@t0mlaptop (orig r11644):  poisonbit | 2009-10-20 23:16:03 +0100
Fixes to pass podchecker OK

r11714@t0mlaptop (orig r11679):  rafl | 2009-10-28 23:54:56 +0000
Enable Catalyst::Utils::home() to find home within Dist::Zilla built dists.

Courtesy of nperez.
r11716@t0mlaptop (orig r11681):  t0m | 2009-10-29 00:43:07 +0000
Make URI a link to make it super obvious
r11796@t0mlaptop (orig r11761):  t0m | 2009-11-05 00:11:15 +0000
Need newer LWP for tests to pass as suggested on list by Jose Luis Martinez
r11811@t0mlaptop (orig r11776):  altreus | 2009-11-06 17:09:51 +0000
Add doc for no-args call to ->uri_for
r11813@t0mlaptop (orig r11778):  dhoss | 2009-11-06 17:13:27 +0000
fixed options passed to devel server so that author tests pass
r11814@t0mlaptop (orig r11779):  altreus | 2009-11-06 17:14:49 +0000
Amend doc to not mention using undef in ->uri_for
r11816@t0mlaptop (orig r11781):  t0m | 2009-11-07 16:50:59 +0000
Back out change from -port to -l - svn merge -r 11778:11777
r11823@t0mlaptop (orig r11788):  rafl | 2009-11-09 22:21:19 +0000
Make request->body fail when used as a writer.
r11824@t0mlaptop (orig r11789):  t0m | 2009-11-10 19:51:33 +0000
Fix changelog, me--
r11825@t0mlaptop (orig r11790):  t0m | 2009-11-10 19:56:09 +0000
Warn on case_sensitive being set, remove documentation
r11827@t0mlaptop (orig r11792):  t0m | 2009-11-10 21:36:06 +0000
Return 1, only currently works by chance
r11828@t0mlaptop (orig r11793):  t0m | 2009-11-10 21:37:26 +0000
Also retarded
r11829@t0mlaptop (orig r11794):  t0m | 2009-11-10 21:41:27 +0000
And lets not change behaviour with the log flush change..
r11836@t0mlaptop (orig r11801):  t0m | 2009-11-12 01:12:05 +0000
Bring the changelog up to date.
r11839@t0mlaptop (orig r11804):  t0m | 2009-11-12 01:44:46 +0000
 r11462@t0mlaptop (orig r11432):  rafl | 2009-09-27 16:06:26 +0100
 More aggregated tests.
 r11463@t0mlaptop (orig r11433):  rafl | 2009-09-27 16:06:36 +0100
 Fix a couple of aggregation warnings.
 r11464@t0mlaptop (orig r11434):  rafl | 2009-09-27 16:06:51 +0100
 More aggregation.
 r11465@t0mlaptop (orig r11435):  rafl | 2009-09-27 16:28:04 +0100
 Make things run again with aggregation disabled.
 r11838@t0mlaptop (orig r11803):  t0m | 2009-11-12 01:39:56 +0000
 Patch up changes to tests into new location. This merges parts of the following commits which were missed by svk:

 -r11456:11457 http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Runtime/5.80/trunk
 -r11467:11468 http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Runtime/5.80/trunk

r11841@t0mlaptop (orig r11806):  bricas | 2009-11-12 17:58:02 +0000
remove duplicate changelog entry

Makefile.PL
lib/Catalyst.pm
t/aggregate/live_component_controller_action_chained.t
t/lib/TestApp/Controller/Action/Chained.pm

index be08062..dc3cea6 100644 (file)
@@ -52,6 +52,7 @@ recommends 'B::Hooks::OP::Check::StashChange';
 
 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')) {
@@ -64,6 +65,7 @@ else {
         map  { glob } qw[t/*.t t/aggregate/*.t];
 }
 author_requires 'CatalystX::LeakChecker', '0.03'; # Skipped if this isn't installed
+author_requires 'File::Copy::Recursive'; # For http server test
 
 author_tests 't/author';
 author_requires(map {; $_ => 0 } qw(
index d681c90..6e74e58 100644 (file)
@@ -1259,9 +1259,10 @@ sub uri_for {
     }
 
     if ( blessed($path) ) { # action object
-        my $captures = ( scalar @args && ref $args[0] eq 'ARRAY'
-                         ? shift(@args)
-                         : [] );
+        my $captures = [ map { s|/|%2F|; $_; }
+                        ( scalar @args && ref $args[0] eq 'ARRAY'
+                         ? @{ shift(@args) }
+                         : ()) ];
         my $action = $path;
         $path = $c->dispatcher->uri_for_action($action, $captures);
         if (not defined $path) {
@@ -1279,6 +1280,7 @@ sub uri_for {
 
     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);
 
index 3784fe6..157f016 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 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,29 @@ sub run_tests {
             '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 ;)
+    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;
+
index 64de556..cbba762 100644 (file)
@@ -204,6 +204,13 @@ sub return_arg_decoded : Chained('/') PathPart('chained/return_arg_decoded') Arg
     $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) = @_;