[Jifty-commit] jifty branch, plack, updated. d0c066efb2346370235a58a0d9559b214c8b283f
Jifty commits
jifty-commit at lists.jifty.org
Fri Jan 8 21:54:23 EST 2010
The branch, plack has been updated
via d0c066efb2346370235a58a0d9559b214c8b283f (commit)
via 746285797e5bc0961f5e6344d5653cc812c619a1 (commit)
via bd9a6f75d1c42655c638a13b089dbd7e421d9a8a (commit)
via 4a8eecd5b07ef79f5e3e71bad720f8bbab698d97 (commit)
from a4c5c0ce895139d9bc80b8170ed86694e84cf566 (commit)
Summary of changes:
lib/Jifty/Continuation.pm | 17 ++++++-----------
lib/Jifty/Request.pm | 21 ++++++---------------
lib/Jifty/Util.pm | 8 +++-----
lib/Jifty/Web.pm | 5 ++++-
lib/Jifty/Web/Form.pm | 3 +--
lib/Jifty/Web/Form/Clickable.pm | 10 +++-------
lib/Jifty/Web/Form/Link.pm | 3 +--
7 files changed, 24 insertions(+), 43 deletions(-)
- Log -----------------------------------------------------------------
commit 4a8eecd5b07ef79f5e3e71bad720f8bbab698d97
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Fri Jan 8 20:37:34 2010 -0500
Clone requests more deeply, now that ->uri is a ref
Previously, cloning a request made the ->path of each be independent.
However, now that ->path mutates ->uri, which is itself an object,
this is no longer the case. When cloning, it is thus necessary to
clone the URI object as well.
diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index b66159a..1550d50 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -132,10 +132,13 @@ sub clone {
my $self = shift;
# "Semi-shallow" clone
- return bless({map {
+ my $ret = bless({map {
my $val = $self->{$_};
$_ => (ref($val) eq "HASH" ? { %$val } : ref($val) eq "ARRAY" ? [ @$val ] : $val);
} keys %$self}, ref($self));
+
+ $ret->uri( $self->uri->clone );
+ return $ret;
}
=head2 promote
commit bd9a6f75d1c42655c638a13b089dbd7e421d9a8a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Fri Jan 8 20:30:19 2010 -0500
Keep trailing slashes in Jifty->web->request->path
Removing trailing slashes from Jifty->web->request->path makes it
unsuitable for providing web URLs; specifically, they do not work for
"self-links." While the same template may render for "/splash" and
"/splash/", relative links will resolve differently in each.
Trailing slashes had been being stripped by
Jifty::Util::canonicalize_path, which is primarily meant for file
paths. In addition to File::Spec->catdir ignoring trailing slashes,
they were explicitly ignored while walking through ->splitdir.
In order to preserve the behavior of t/TestApp/t/14-template-paths.t,
trailing slashes need to be stripped off of template paths before view
objects are asked to resolve them to templates.
diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index 1550d50..e06d56b 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -197,7 +197,7 @@ sub from_data_structure {
my $path = $data->{'path'};
$path ||= $self->path || '/';
- $self->path( Jifty::Util->canonicalize_path( $path ) );
+ $self->path( Jifty::Util->canonicalize_path( $path, 1 ) );
$self->just_validating( $data->{validating} ) if $data->{validating};
if ( ref $data->{continuation} eq "HASH" ) {
diff --git a/lib/Jifty/Util.pm b/lib/Jifty/Util.pm
index e0ee289..dbeb5fc 100644
--- a/lib/Jifty/Util.pm
+++ b/lib/Jifty/Util.pm
@@ -50,6 +50,7 @@ both C</> and C<\> as valid separators in PATH.
sub canonicalize_path {
my $self = shift;
my $path = shift;
+ my $keepempty = shift;
my @path = File::Spec->splitdir($path);
@@ -65,13 +66,10 @@ sub canonicalize_path {
} else {
pop @newpath;
}
-
}
-
- return File::Spec::Unix->catdir(@newpath);
-
-
+ push @newpath, '' if $keepempty and @path and $path[-1] eq '';
+ return join("/", at newpath);
}
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index 87dd8a2..5cd408a 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -948,6 +948,9 @@ sub template_exists {
my $value = ref $template ? $$template : $template;
+ # Strip trailing slashes
+ $value =~ s{/$}{} if $value ne "/";
+
foreach my $handler ( map {Jifty->handler->view($_)} Jifty->handler->view_handlers ) {
if ( my $path = $handler->template_exists($value) ) {
$$template = $path if ref $template;
commit 746285797e5bc0961f5e6344d5653cc812c619a1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Fri Jan 8 16:34:32 2010 -0500
Continuations: Clean up return_path_matches logic
The previous "URI unescape until we can't anymore, then match" logic
was necessary because different server request methods had different
standards of escaping. PSGI has a clear standard, so we can do the
much simpler check of if the paths match, the only argument is
J:RETURN, and it is set correctly.
diff --git a/lib/Jifty/Continuation.pm b/lib/Jifty/Continuation.pm
index 0ffc3d7..5173245 100644
--- a/lib/Jifty/Continuation.pm
+++ b/lib/Jifty/Continuation.pm
@@ -152,20 +152,15 @@ to ask "are we about to call a continuation?"
sub return_path_matches {
my $self = shift;
- my $called_uri = Jifty->web->request->request_uri;
- my $request_path = $self->request->path;
- # XXX TODO: WE should be using URI canonicalization
+ return unless Jifty->web->request->path eq $self->request->path;
- my $escape;
- $called_uri =~ s{/+}{/}g;
- $called_uri = Encode::encode_utf8($called_uri);
- $called_uri = $escape while $called_uri ne ($escape = URI::Escape::uri_unescape($called_uri));
- $request_path =~ s{/+}{/}g;
- $request_path = Encode::encode_utf8($request_path);
- $request_path = $escape while $request_path ne ($escape = URI::Escape::uri_unescape($request_path));
+ my $args = Jifty->web->request->arguments;
+ return unless scalar keys %{$args} == 1;
- return $called_uri =~ /^\Q$request_path\E[?&;]J:RETURN=@{[$self->id]}$/;
+ return unless exists $args->{"J:RETURN"} and $args->{"J:RETURN"} eq $self->id;
+
+ return 1;
}
=head2 call
commit d0c066efb2346370235a58a0d9559b214c8b283f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Fri Jan 8 20:40:12 2010 -0500
Use Jifty->web->request->top_request->path instead of ->request_uri
request_uri is URI-encoded, and is not updated when ->path is. This
also avoids the dance of having to trim off the request parameters.
diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index e06d56b..b6f36fa 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -89,17 +89,6 @@ method of that name is called, with the I<PARAMHASH>'s value as its
sole argument.
=cut
-
-sub BUILDARGS {
- my ($class, %args) = @_;
-
- if (my $path = delete $args{path}) {
- $args{env}{REQUEST_URI} ||= $path;
- }
-
- return \%args;
-}
-
sub BUILD {
my $self = shift;
@@ -115,9 +104,8 @@ sub BUILD {
$self->{'state_variables'} = {};
$self->{'fragments'} = {};
$self->{env}{'REQUEST_METHOD'} ||= 'GET';
- $self->{env}{'REQUEST_URI'} ||= '/';
- $self->path($self->{env}{REQUEST_URI});
+ $self->path("/") unless $self->path;
$self->arguments({});
$self->template_arguments({});
}
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index 5cd408a..31ff39d 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -144,7 +144,7 @@ sub url {
$http_host_env = (Jifty->web->is_ssl ? "https" : "http") ."://$http_host_env";
}
$uri = URI->new($http_host_env);
- if ($dirty && (my $req_uri_env = $ENV{REQUEST_URI})) {
+ if ($dirty && Jifty->web->request && (my $req_uri_env = Jifty->web->request->request_uri)) {
my $req_uri = URI->new($req_uri_env);
$uri->scheme($req_uri->scheme) if $req_uri->can('scheme');
$dirty = $uri->scheme;
diff --git a/lib/Jifty/Web/Form.pm b/lib/Jifty/Web/Form.pm
index 2f2d26c..d8aae26 100644
--- a/lib/Jifty/Web/Form.pm
+++ b/lib/Jifty/Web/Form.pm
@@ -200,8 +200,7 @@ sub start {
}
}
- my $root = $self->submit_to;
- ($root) = Jifty->web->request->request_uri =~ /([^\?]*)/ unless defined $root;
+ my $root = $self->submit_to || Jifty->web->request->top_request->path;
my $form_start = qq!<form method="post" action="! . Jifty->web->escape( $root ) . qq!"!;
$form_start .= qq! name="@{[ $self->name ]}"! if defined $self->name;
$form_start .= qq! target="@{[ $self->target ]}"! if defined $self->target;
diff --git a/lib/Jifty/Web/Form/Clickable.pm b/lib/Jifty/Web/Form/Clickable.pm
index eda8295..9235958 100644
--- a/lib/Jifty/Web/Form/Clickable.pm
+++ b/lib/Jifty/Web/Form/Clickable.pm
@@ -155,7 +155,6 @@ get an unexpected error from your browser.
sub new {
my $class = shift;
- my ($root) = Jifty->web->request->request_uri =~ /([^\?]*)/;
my %args = (
parameters => {},
@@ -170,7 +169,7 @@ sub new {
my $self = $class->SUPER::new(
{ class => '',
label => 'Click me!',
- url => $root,
+ url => Jifty->web->request->top_request->path,
escape_label => 1,
tooltip => '',
continuation => Jifty->web->request->continuation,
@@ -428,15 +427,13 @@ sub post_parameters {
my %parameters
= ( _map( %{ $self->{fallback} || {} } ), $self->parameters );
- my ($root) = Jifty->web->request->request_uri =~ /([^\?]*)/;
-
# Submit actions should only show up once
my %uniq;
$self->submit( [ grep { not $uniq{$_}++ } @{ $self->submit } ] )
if $self->submit;
# Add a redirect, if this isn't to the right page
- if ( $self->url ne $root and not $self->returns ) {
+ if ( $self->url ne Jifty->web->request->top_request->path and not $self->returns ) {
Jifty::Util->require('Jifty::Action::Redirect');
my $redirect = Jifty::Action::Redirect->new(
arguments => { url => $self->url } );
@@ -479,8 +476,7 @@ sub complete_url {
my %parameters = $self->get_parameters;
- my ($root) = Jifty->web->request->request_uri =~ /([^\?]*)/;
- my $url = $self->returns ? $root : $self->url;
+ my $url = $self->returns ? Jifty->web->request->top_request->path : $self->url;
if (%parameters) {
$url .= ( $url =~ /\?/ ) ? ";" : "?";
$url .= Jifty->web->query_string(%parameters);
diff --git a/lib/Jifty/Web/Form/Link.pm b/lib/Jifty/Web/Form/Link.pm
index 3c0c94e..be5078c 100644
--- a/lib/Jifty/Web/Form/Link.pm
+++ b/lib/Jifty/Web/Form/Link.pm
@@ -69,9 +69,8 @@ Any parameter which L<Jifty::Web::Form::Element/new> can take.
sub new {
my $class = shift;
my $args = ref($_[0]) ? $_[0] : {@_};
- my ($root) = Jifty->web->request->request_uri =~ /([^\?]*)/;
my $self = $class->SUPER::new(
- { url => $root,
+ { url => Jifty->web->request->top_request->path,
label => "Click me!",
tooltip => undef,
escape_label => 1,
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list