bref icon indicating copy to clipboard operation
bref copied to clipboard

Rewrite query string parsing to avoid use parse_str

Open alekitto opened this issue 4 years ago • 5 comments

I've encountered the same problems described in #756, so I've checked how PHP implemented the parse string filter and rewrote it in PHP to avoid using parse_str itself.

Spaces and dots are preserved in the resulting array keys. The behavior of the parser on case of unclosed bracket is retained too.

alekitto avatar Sep 27 '21 12:09 alekitto

This is quite a complex change and somewhat a maintenance overhead for bref. I'll need some time before I can review this thoroughly.

It would be good to know how many people are having issues with this to help with prioritization.

deleugpn avatar Sep 30 '21 12:09 deleugpn

Hi,

We are having this problem with Api Platform too.

curl -X 'GET'
'https://xxxxxxx/api/v4/group_classes?page=1&activity.id=6'
-H 'accept: application/ld+json'

is handled with this query string :

"hydra:view": { "@id": "/api/v4/group_classes?activity_id=6", "@type": "hydra:PartialCollectionView" },

The usage of dot is a basic feature in Api Plaform : https://api-platform.com/docs/core/filters/#filtering-on-nested-properties

I am amazed that so few people have encountered the problem

Cafeine42 avatar Jan 07 '22 16:01 Cafeine42

For more info, Api Platform have an implementation to handle this too : https://github.com/api-platform/core/blob/10827bb570c44cdee2c1bb7a307a8a18df9b4f00/src/Util/RequestParser.php#L50 Solution referenced in comments : https://stackoverflow.com/questions/68651/get-php-to-stop-replacing-characters-in-get-or-post-arrays/18209799#18209799

Cafeine42 avatar Jan 07 '22 17:01 Cafeine42

@Cafeine42 nice, that sounds interesting, especially knowing it's already used by API Platform at scale. And it looks "simple" too.

A PR with that implementation (with correct @author attribution) could be easier to merge probably.

mnapoli avatar Jan 08 '22 15:01 mnapoli

IMHO the "api platform" solution sounds hackish, is based on the same function that caused the original bug and is not really performant (~50% slower in my tests).

Could be "simpler" to see, but in an environment where every millisecond counts and it's billed, performance should be taken into consideration.

alekitto avatar Jan 08 '22 18:01 alekitto

Thanks for all the effort! This has been fixed in #1437

mnapoli avatar Mar 27 '23 13:03 mnapoli