[Catalyst-dev] uri_for and utf8::encode
Matt S Trout
dbix-class at trout.me.uk
Tue May 8 01:48:35 GMT 2007
On Fri, Apr 06, 2007 at 02:10:38PM -0500, stephen joseph butler wrote:
> I was poking around in Catalyst::uri_for while writing a plugin and I
> think I found a bug in this part of the code:
>
> for my $value ( values %$params ) {
> next unless defined $value;
> for ( ref $value eq 'ARRAY' ? @$value : $value ) {
> $_ = "$_";
> utf8::encode( $_ );
> }
> };
>
> If my understanding of utf8::encode is correct, this encodes the
> scalar as UTF-8 and removes the internal UTF-8 marker (so the string
> appears raw).
>
> But utf8::decode is never run after the URI has been built. The sub
> returns with the parameter values encoded but without the internal
> UTF-8 marker, effectively corrupting them.
>
> I imagine that in most usage scenarios this isn't a problem, since
> people either build an anonymous hash on the spot, or call uri_for at
> the end of their action. Still, this seems like a bad side effect to
> me.
>
> Proposed fixes: either copy the params hash, or run utf8::decode()
> before returning.
Bench it. If the performance effect is significant, better just to fix the
docs - we've done a lot of work optimising uri_for recently and it can still
be a bottleneck.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://www.shadowcatsystems.co.uk/
More information about the Catalyst-dev
mailing list