lithium icon indicating copy to clipboard operation
lithium copied to clipboard

Unable to set query parameter to "0" on request

Open IGx89 opened this issue 8 years ago • 1 comments

Hello! A bit stumped. I'm using lithium\net\http\Request class and trying to build a request like such:

http://www.test.com/test.php?type=0

When I create the Request with a "query" array with a key of "type" and value of "0" though, the URL sent to curl ends up being just http://www.test.com/test.php.

Digging through the code I found the culprit: the query array is being filtered with array_filter in the queryString method, which removes all query parameters with falsy values! Thus a query parameter containing a single string character of "0" is stripped out.

Is this a bug? Any recommendations on how to work around it?

Thanks!

IGx89 avatar Oct 11 '17 03:10 IGx89

Thanks for opening the issue.

I guess you're looking at one of the many array_filter() uses in:

  • https://github.com/UnionOfRAD/lithium/blob/master/net/http/Request.php#L241

The corresponding tests are here:

  • https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RequestTest.php#L99-L137
  • https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RequestTest.php#L358-L371

At a first look I can't see why the query string is being filtered (even multiple times). The above tests don't seem to cover that case, so I'm tempted to assume we can remove the filtering altogether.

I'd need your help on this: can you try and verify that assumption? Maybe even provide a patch that fixes this seemingly strange behavior?

mariuswilms avatar Feb 03 '18 10:02 mariuswilms