[Jifty-commit] jifty branch, master, updated. 1.10518-101-g3825ccf
Jifty commits
jifty-commit at lists.jifty.org
Sun Feb 17 00:22:33 EST 2013
The branch, master has been updated
via 3825ccfe10c6259024f40361a4a7fee18c1e6ba6 (commit)
from 5d1407bd8e0b566a37947c39772ee01148ce0fdc (commit)
Summary of changes:
lib/Jifty/Plugin/REST/Dispatcher.pm | 13 +++++++++----
t/TestApp-Plugin-REST/t/03-format.t | 16 +++++++++++++---
2 files changed, 22 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 3825ccfe10c6259024f40361a4a7fee18c1e6ba6
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Feb 14 21:11:01 2013 -0800
Unescape and potentially decode UTF8 in REST paramters
The dispatcher doesn't unescape matched URL values. Without the
unescaping, it was impossible to use basic REST urls for values
containing reserved characters.
A basic test of functionality is included. The test file fails before
this commit.
diff --git a/lib/Jifty/Plugin/REST/Dispatcher.pm b/lib/Jifty/Plugin/REST/Dispatcher.pm
index 880af1b..8c869d7 100644
--- a/lib/Jifty/Plugin/REST/Dispatcher.pm
+++ b/lib/Jifty/Plugin/REST/Dispatcher.pm
@@ -13,6 +13,7 @@ use Jifty::YAML ();
use Jifty::JSON ();
use Data::Dumper ();
use XML::Simple;
+use URI::Escape ();
before qr{^ (/=/ .*) \. (js|json|yml|yaml|perl|pl|xml|html) $}x => run {
Jifty->web->request->env->{HTTP_ACCEPT} = $2;
@@ -487,6 +488,10 @@ sub _resolve {
return $hit;
}
+sub unescape {
+ return map { Jifty::I18N->maybe_decode_utf8( URI::Escape::uri_unescape($_) ) } @_;
+}
+
=head2 list_models
@@ -565,7 +570,7 @@ Returns a list of items in MODELCLASS sorted by COLUMNNAME, with only COLUMNNAME
sub list_model_items {
# Normalize model name - fun!
- my ( $model, $column ) = ( model($1), $2 );
+ my ( $model, $column ) = ( model($1), unescape($2) );
my $col = $model->new->collection_class->new;
$col->unlimit;
@@ -590,7 +595,7 @@ Returns 404 if it doesn't exist.
=cut
sub show_item_field {
- my ( $model, $column, $key, $field ) = ( model($1), $2, $3, $4 );
+ my ( $model, $column, $key, $field ) = ( model($1), unescape($2, $3, $4) );
my $rec = $model->new;
$rec->load_by_cols( $column => $key );
$rec->id or abort(404);
@@ -612,7 +617,7 @@ Returns 404 if it doesn't exist.
=cut
sub show_item {
- my ($model, $column, $key) = (model($1), $2, $3);
+ my ($model, $column, $key) = (model($1), unescape($2, $3));
my $rec = $model->new;
# Check that the field is actually a column
@@ -660,7 +665,7 @@ Order by the given column, descending.
sub search_items {
my ($model, $fragment) = (model($1), $2);
my @pieces = grep {length} split '/', $fragment;
- my $ret = ['search', $model, @pieces];
+ my $ret = ['search', $model, unescape(@pieces)];
# limit to the key => value pairs they gave us
my $collection = eval { $model->collection_class->new }
diff --git a/t/TestApp-Plugin-REST/t/03-format.t b/t/TestApp-Plugin-REST/t/03-format.t
index ab54460..b597356 100644
--- a/t/TestApp-Plugin-REST/t/03-format.t
+++ b/t/TestApp-Plugin-REST/t/03-format.t
@@ -2,7 +2,7 @@
use warnings;
use strict;
-use Jifty::Test::Dist tests => 104;
+use Jifty::Test::Dist tests => 111;
use Jifty::Test::WWW::Mechanize;
my $server = Jifty::Test->make_server;
@@ -25,6 +25,12 @@ my $u1 = TestApp::Plugin::REST::Model::User->new(
$u1->create(name => 'test', email => 'test at example.com', group_id => $g1->id);
ok($u1->id);
+my $u2 = TestApp::Plugin::REST::Model::User->new(
+ current_user => TestApp::Plugin::REST::CurrentUser->superuser,
+);
+$u2->create(name => 'test#ing', email => 'testing at example.com');
+ok($u2->id);
+
our $FORMAT_NUMBER;
sub result_of {
@@ -107,7 +113,7 @@ result_of '/=/model/User' => sub {
};
result_of '/=/model/user/id' => sub {
- is(@{ $_[0] }, 1, "one user");
+ is(@{ $_[0] }, 2, "two users");
};
result_of '/=/model/user/id/1' => sub {
@@ -125,13 +131,17 @@ result_of '/=/model/user/id/1/email' => sub {
is($_[0], 'test at example.com');
};
+result_of '/=/model/user/name/test%23ing/email' => sub {
+ is($_[0], 'testing at example.com');
+};
+
result_of_post '/=/model/user' => {
name => 'moose',
email => 'moose at example.com',
} => sub {
my ($action_result, $record) = @_;
- my $id = 2 + ($FORMAT_NUMBER - 1);
+ my $id = 3 + ($FORMAT_NUMBER - 1);
is_deeply($action_result, {
action_class => 'TestApp::Plugin::REST::Action::CreateUser',
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list