[Catalyst-dev] uri_for and utf8::encode

stephen joseph butler stephen.butler at gmail.com
Fri Apr 6 20:10:38 GMT 2007


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.



More information about the Catalyst-dev mailing list