X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=6523d21917f3a786eafc7c3df0957cb07baf166b;hp=64c097c0bb84f2adc85ca1b7d13c2962fbaa6662;hb=02336198551ec2d7edfa74911919b8804bfc69c8;hpb=082b44215ddd03a11cffe22f7f40a33ee0fa4607 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 64c097c..6523d21 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1506,6 +1506,15 @@ relative to the application root (if it does). It is then merged with C<< $c->request->base >>; any C<@args> are appended as additional path components; and any C<%query_values> are appended as C parameters. +B If you are using this 'stringy' first argument, we skip encoding and +allow you to declare something like: + + $c->uri_for('/foo/bar#baz') + +Where 'baz' is a URI fragment. We consider this first argument string to be +'expert' mode where you are expected to create a valid URL and we for the most +part just pass it through without a lot of internal effort to escape and encode. + If the first argument is a L it represents an action which will have its path resolved using C<< $c->dispatcher->uri_for_action >>. The optional C<\@captures> argument (an arrayref) allows passing the captured @@ -1548,13 +1557,24 @@ sub uri_for { $path .= '/'; } - undef($path) if (defined $path && $path eq ''); - my $fragment = ((scalar(@args) && ref($args[-1]) eq 'SCALAR') ? pop @args : undef ); + unless(blessed $path) { + if ($path =~ s/#(.+)$//) { + if(defined($1) and $fragment) { + carp "Abiguious fragment declaration: You cannot define a fragment in '$path' and as an argument '$fragment'"; + } + if(defined($1)) { + $fragment = $1; + } + } + } + my $params = ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} ); + undef($path) if (defined $path && $path eq ''); + carp "uri_for called with undef argument" if grep { ! defined $_ } @args; my $target_action = $path->$_isa('Catalyst::Action') ? $path : undef; @@ -1663,9 +1683,11 @@ sub uri_for { $args =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go; if(defined $fragment) { - $fragment = encode_utf8(${$fragment}); - $fragment =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go; - $fragment =~ s/ /+/g; + if(blessed $path) { + $fragment = encode_utf8(${$fragment}); + $fragment =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go; + $fragment =~ s/ /+/g; + } $query .= "#$fragment"; }