top | item 46270984

(no title)

flanfly | 2 months ago

Good showcase. Your code will match the first parameter that has <param> as a suffix, no necessarily <param> exactly (username=blag&name=blub will return blag). It also doesn't handle any percent encoding.

discuss

order

stouset|2 months ago

Further, when retrieving multiple parameters, you have a Shlemiel-the-painter algorithm.

https://www.joelonsoftware.com/2001/12/11/back-to-basics/

1718627440|2 months ago

Thanks, good author. I also like to read him. Honestly not parsing the whole query string at once feels kind of dumb. To quote myself:

> In practice you would probably parse all parameters at once and maybe use a library.

1718627440|2 months ago

> Your code will match the first parameter that has <param> as a suffix, no necessarily <param> exactly

Depending on your requirements, that might be a feature.

> It also doesn't handle any percent encoding.

This does literal matches, so yes you would need to pass the param already percent encoded. This is a trade off I did, not for that case, but for similar issues. I don't like non-ASCII in my source code, so I would want to encode this in some way anyway.

But you are right, you shouldn't put this into a generic library. Whether it suffices for your project or not, depends on your requirements.

stouset|2 months ago

This exact mindset is why so much software is irreparably broken and riddled with CVEs.

Written standard be damned; I’ll just bang out something that vaguely looks like it handles the main cases I can remember off the top of my head. What could go wrong?

recursive|2 months ago

Ampersands are ASCII, but also need to be encoded to be in a parameter value.