FAQ
Attached is a patch for Catalyst::Plugin::PageCache which fixes an
issue when Catalyst::Plugin::Unicode is also loaded.

Catalyst::Plugin::Unicode decodes UTF-8 strings to Perl character
sequences, which causes fatal errors:

[Sat Apr 29 14:21:32 2006] [catalyst] [error] Caught exception in
engine "Wide character in subroutine entry at
/usr/lib/perl5/vendor_perl/5.8.7/Cache/FileBackend.pm line 201."

When this happens, the request dies with no response. When running
under Apache, Apache returns a 500 error.

This patch adds decoding of parameters from C::P::Unicode to the
TestApp (but does not actually load C::P::Unicode). It also adds
tests which exhibit the failure when this decoding is in effect.

Finally, the patch modifies the _get_page_cache_key function to encode
strings so the Cache backend can handle them.

--
Daniel Westermann-Clark
-------------- next part --------------
Auto-merging (0, 8774) /local/Catalyst-Plugin-PageCache to /mirror/Catalyst/trunk/Catalyst-Plugin-PageCache (base /mirror/Catalyst/trunk/Catalyst-Plugin-PageCache:8191).
Patching locally against mirror source http://dev.catalyst.perl.org/repos/Catalyst.
U t/lib/TestApp.pm
U t/08params.t
U lib/Catalyst/Plugin/PageCache.pm
U Changes
==== Patch <-> level 1
Source: 20164c6d-cd09-0410-925d-b4c4e616b846:/local/Catalyst-Plugin-PageCache:8774
Target: 4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Plugin-PageCache:3771
(http://dev.catalyst.perl.org/repos/Catalyst)
Log:
Fix interaction with Catalyst::Plugin::Unicode and UTF-8 query parameters
=== t/lib/TestApp.pm
==================================================================
--- t/lib/TestApp.pm (revision 3771)
+++ t/lib/TestApp.pm (patch - level 1)
@@ -21,4 +21,20 @@


}



+# From Catalyst::Plugin::Unicode

+sub prepare_parameters {

+ my $c = shift;

+

+ $c->NEXT::prepare_parameters;

+

+ for my $value ( values %{ $c->request->{parameters} } ) {

+

+ if ( ref $value && ref $value ne 'ARRAY' ) {

+ next;

+ }

+

+ utf8::decode($_) for ( ref($value) ? @{$value} : $value );

+ }

+}

+

1;

=== t/08params.t
==================================================================
--- t/08params.t (revision 3771)
+++ t/08params.t (patch - level 1)
@@ -12,7 +12,7 @@
eval "use Catalyst::Plugin::Cache::FileCache";
plan $@
? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 8 );
+ : ( tests => 16 );
}

# remove previous cache
@@ -38,4 +38,18 @@
ok( $res = request('http://localhost/cache/count?b=4&c=5&a=2&a=3&a=1'), 'request ok' );
is( $res->content, 2, 'count is still 2 from cache' );

+# test Unicode params
+ok( $res = request('http://localhost/cache/count?a=%E2%98%BA&b=%E2%98%BB'), 'request ok' );
+is( $res->content, 3, 'count is 3' );

+# page will be served from cache even though params are different order
+ok( $res = request('http://localhost/cache/count?b=%E2%98%BB&a=%E2%98%BA'), 'request ok' );
+is( $res->content, 3, 'count is still 3 from cache' );
+
+# test reversed Unicode params
+ok( $res = request('http://localhost/cache/count?a=%E2%98%BB&b=%E2%98%BA'), 'request ok' );
+is( $res->content, 4, 'count is 4' );
+
+# page will be served from cache even though params are different order
+ok( $res = request('http://localhost/cache/count?b=%E2%98%BA&a=%E2%98%BB'), 'request ok' );
+is( $res->content, 4, 'count is still 4 from cache' );
=== lib/Catalyst/Plugin/PageCache.pm
==================================================================
--- lib/Catalyst/Plugin/PageCache.pm (revision 3771)
+++ lib/Catalyst/Plugin/PageCache.pm (patch - level 1)
@@ -4,7 +4,7 @@
use base qw/Class::Accessor::Fast/;
use NEXT;

-our $VERSION = '0.12';
+our $VERSION = '0.13';

# Do we need to cache the current page?
__PACKAGE__->mk_accessors('_cache_page');
@@ -289,13 +289,14 @@
if ( scalar $c->req->param ) {
my @params;
foreach my $arg ( sort keys %{ $c->req->params } ) {
- if ( ref $c->req->params->{$arg} ) {
- my $list = $c->req->params->{$arg};
- push @params, map { "$arg=" . $_ } sort @{$list};
+ my @values = ref $c->req->params->{$arg}
+ ? @{ $c->req->params->{$arg} }
+ : $c->req->params->{$arg};
+ for (@values) {
+ utf8::encode($_) if utf8::is_utf8($_);
}
- else {
- push @params, "$arg=" . $c->req->params->{$arg};
- }
+
+ push @params, map { "$arg=" . $_ } sort @values;
}
$key .= '?' . join( '&', @params );
}
=== Changes
==================================================================
--- Changes (revision 3771)
+++ Changes (patch - level 1)
@@ -1,5 +1,9 @@
Revision history for Perl extension Catalyst::Plugin::PageCache

+0.13
+ - Fix interaction with Catalyst::Plugin::Unicode and UTF-8
+ query parameters (dwc)
+
0.12 2006-03-09 16:30:00
- Fixed race condition in HTTP header test.
- Fixed Content-type to retain charset (moseley)

==== BEGIN SVK PATCH BLOCK ====
Version: svk 1.07 (linux)

eJytVs1v3EQUNydEpAoQR4o0tM6XFGftGY893ijbTUpzAVVVCQhOy9gzzlpx7MWebRvFkZJFqOLE
jf4xXJD4w8rzzGa722yTgrBW2hn7vd/7mPd+8w6qw52+1/R6bmN7bvPt9193u0+4Soarnt/YQSNF
psrKpk0un8ncJk1eHtl+U/ATCV/rclwl7ULx6kiqdpElx1L1eh7AMQP3SENcwWrUmKuyqO1Iww9U
JaWNG8/te17TJ+1vYHtRU0v4poEHlXyW1VlZgGkWhj5I2F7jAUA5ksWgKksFX3w3YH3c6rpNkpe1
HLTwfb/p01Yc2xCSlhdZJRPw6RTeKg00VdZywRI5iDuL35JsPb7yIM1yaYfNwyEvjmQ9L6hjoVN/
5g17baTaIFlikDaqY0ziBefogkUPg5jLRrziJ/W2mpd+p10MKTJY/iJWYEx2DmWt9kaj7dGJ9u02
PGLw9Fc+GuWnAyVfKCFzxbUNgpswiGUgCEupTGRCvShmOIC/RKSeYBLbJCRQK48ta/Lk1+0PJ7E1
+ca6mMT30UFVnqCHXPH8tFZQQvn4KCu63e+KLCmFvLNSj2M0qiQkQA50FqSSVY3O7qwgeE5OkZ2g
XVQPs1Tt3Fkxb+3E6T1+9MNht3tdcyaUlpVWf8bzsUQbSP/XaPVMq1fyZ9gpp3f2RvUcnaPN1rIB
aJ8sBc1Kplcwa2vzu0Ki9b2nT/d+XDd6aO4pIIU7b16dz6OOVcq6XSHbDGzYg03tq7azYZA30QPU
PzPrc9S9src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ussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 29, '06 at 6:28p
activeApr 29, '06 at 6:28p
posts1
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

Daniel Westermann-Clark: 1 post

People

Translate

site design / logo © 2021 Grokbase