[Catalyst] Passing UTF-8 arg in URL to DBIC search

Bill Moseley moseley at hank.org
Tue Sep 30 21:40:57 BST 2008


On Tue, Sep 30, 2008 at 08:10:13AM -0700, J. Shirley wrote:
> On Sat, Sep 27, 2008 at 6:51 AM, Hugh Hunter <hhunter at gmail.com> wrote:
> > Hello all,
> >
> > I've been struggling with this for some time and know there must be an
> > answer out there.
> >
> > I'm using URL arguments to pass parameters to my controller.  It's a site
> > about names, so take the url http://domain.com/name/Jesús (note the accented
> > u).  The Name.pm controller has an :Args(1) decorator so Jesús is stored in
> > $name and then passed to my DBIC model in a ->search({name => $name}) call.
> >  This doesn't manage to find the row that exists in mysql.  When I dump
> > $name I get:
> >
> > 'name' => 'Jes\xc3\xbas'
> >
> > which I think I understand as being perl's internal escaping of utf-8
> > characters.
> >
> > I've done everything recommended on
> > http://dev.catalystframework.org/wiki/gettingstarted/tutorialsandhowtos/using_unicode and
> > the name column in my mysql database uses the utf-8 charset.
> >
> > Where am I going wrong?
> >
> > Best regards,
> >
> > --Hugh
> 
> I haven't dug into the Catalyst source to see of any handling for the
> arguments, but just for testing you may want to try doing a
> utf8::decode($name) and see if that does the trick for you.

I think Encode::decode_utf8() the recommended method over using the
utf8::decode call.  Perhaps something like this early in the request:

    $c->req->arguments(
        [
            map { Encode::decode_utf8($_) } @{$c->req->arguments}
        ]
    );

But, I'd be concerned about doing this.  Will all browsers encode into
utf8 octets?  You could easily make an LWP request with other
encodings.


-- 
Bill Moseley
moseley at hank.org
Sent from my iMutt




More information about the Catalyst mailing list