laminas / laminas-mvc

Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins
https://docs.laminas.dev/laminas-mvc/
BSD 3-Clause "New" or "Revised" License
144 stars 53 forks source link

RESTful: Handle single field request with empty value #18

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

Controller/AbstractRestfulController

There is no way to PUT/PATCH object with single field to empty value.

PUT /item/1
Content-Type: application/x-www-form-urlencoded

name=

Request payload is interpreted as string ($data = 'name=';) regardless Content-Type. Proper value is $data = ['name' => ''];

I think ideally is split behaviour by Content-Type but that follows to huge BC. (see testCanReceiveStringAsRequestContent)

My pull request handle just one situation (example above) by header.


Originally posted by @autowp at https://github.com/zendframework/zend-mvc/pull/251

weierophinney commented 4 years ago

@autowp I've made the change a bit more generic. It does not depend now on the content-type, as it was before. In case we have one element with empty value we are checking if the last character of the content is =. If so, then it is "correct" urlencoded content and we return array, as expected. In case we have any string without = it will return this string, not an array.

In general I think it should be completely changed to work properly with the given content type correctly, as now this is quite hacky, imo.


Originally posted by @michalbundyra at https://github.com/zendframework/zend-mvc/pull/251#issuecomment-562934623