Skip Menu |

This queue is for tickets about the Catalyst-Controller-DBIC-API CPAN distribution.

Report information
The Basics
Id: 44010
Status: resolved
Priority: 0/
Queue: Catalyst-Controller-DBIC-API

People
Owner: Nobody in particular
Requestors: TIMB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Urls containing search=foo cause "Can't use string ("foo") as a HASH ref while "strict refs"" in _format_search()
Urls containing search=foo (no dots) cause "Can't use string ("foo") as a HASH ref while "strict refs"" in _format_search() The code is assuming that expand_hash() will return with the 'search' element being a hash ref. If it doesn't then the app will abort.
On Tue Mar 10 12:38:22 2009, TIMB wrote: Show quoted text
> Urls containing search=foo (no dots) cause "Can't use string ("foo") > as a HASH ref while "strict > refs"" in _format_search() > > The code is assuming that expand_hash() will return with the 'search' > element being a hash ref. > If it doesn't then the app will abort.
sorry for the delay. can you give me a real world example here please? search=foo wouldn't make any sense.
Show quoted text
> search=foo wouldn't make any sense.
I know it wouldn't make any sense, I just don't want the app to crash! :) Looks like the newer code won't have the same problem because it checks {search} is a hash ref else fallsback on JSON::Any. But whet does JSON::Any do if you feed it gibberish? It may throw an exception (e.g. see get_max_size). So I'd suggest an eval {} and log $ on error. Also there's no way to configure the JSON::Any object (or cache it to avoid recreating each time). Perhaps add an accessor to get the json convertor object instance.
On Wed Mar 18 10:16:13 2009, TIMB wrote: Show quoted text
> > search=foo wouldn't make any sense.
> > I know it wouldn't make any sense, I just don't want the app to crash! > :) > > Looks like the newer code won't have the same problem because it > checks {search} is a hash ref > else fallsback on JSON::Any. But whet does JSON::Any do if you feed it > gibberish? It may throw > an exception (e.g. see get_max_size). So I'd suggest an eval {} and > log $ on error.
I've refactored this new JSON stuff to better handle errors. Now it will return a 400 and an error message in the case of being unable to parse this. This behaviour is best described with this test from list_json_search.t: my $uri = URI->new( $artist_list_url ); $uri->query_form({ 'search' => '{"gibberish}' }); my $req = GET( $uri, 'Accept' => 'text/x-json' ); $mech->request($req); cmp_ok( $mech->status, '==', 400, 'attempt with gibberish json not okay' ); my $response = JSON::Syck::Load( $mech->content); is_deeply( { messages => ['can not parse search arg'], success => 'false' }, $response, 'correct data returned for gibberish in search' ); Show quoted text
> Also there's no way to configure the JSON::Any object (or cache it to > avoid recreating each time). > Perhaps add an accessor to get the json convertor object instance.
Might be sensible, but I'm going to shelve this optimisation until the next release when the JSON feature is more mature.