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.