Skip Menu |

This queue is for tickets about the Mojolicious-Plugin-JSONAPI CPAN distribution.

Report information
The Basics
Id: 125504
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Mojolicious-Plugin-JSONAPI

People
Owner: ZIALI [...] cpan.org
Requestors: pspencer [...] fields.utoronto.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.5
Fixed in: (no value)



Subject: requested_fields is broken due to "length" being used on an array
In version 1.5 the requested_fields helper puts all field names into related_fields rather than fields, if the api namespace has more than one element in its path. For example, on GET /some/api/widgets?fields[widgets]=maker, requested_fields gives {fields=>undef, related_fields=>{widgets=>['maker']}} whereas it should give {fields=>['maker']} The cause is the line my $idx = length(split('/', $namespace)) - 1; The split gives ("some", "api") in list context, 2 in scalar context, and length(2) is the number of characters in "2", namely 1. (It would happen to work fine if the namespace had a single element in its path, as length(1) is happily equal to 1). This should be my $idx = scalar(split('/', $namespace)) - 1; or even just my $idx = split('/', $namespace) - 1; With that change, requested_fields gives the proper result.
Thank you for the bug report, this is patched in 1.6. For some reason I was thinking length would return the number of items in the array :S