Re:30 Years of <Br> Tags
by 1718627440 on Tuesday December 16, 2025 @05:59PM
(#46295887)
Most commenters seem to miss that this is the throwaway code for HN, with a maximum allocated time of five minutes. I wouldn't commit it like this. The final code did cope with percent-encoding even though the project didn't took any user generated values at all. And I did read the RFCs, which honestly most developers I meet don't care to do. I also made sure the percent-decodation function did not rely on the ASCII ordering (it only relies on A-Z being continuous), because of portability (EBCDIC) and I have some professional honor.
[ Parent
| on HN ]
Re:30 Years of <Br> Tags
by bruce343434 on Tuesday December 16, 2025 @06:31PM
(#46296208)
I get that, but your initial comment implied you were about to showcase a counter to "Hundreds of lines just to grab a query parameter from a URL", but instead you showed "Poorly and incompletely parsing a single parameter can be done in less than 100 lines".
You said you allocated 5 minutes max to this snippet, well in php this would be 5 seconds and 1 line. And it would be a proper solution.
$name = $_GET['name'] ?? SOME_DEFAULT;
Re:30 Years of <Br> Tags
by 1718627440 on Tuesday December 16, 2025 @07:08PM
(#46296542)
And in the code in C it looks like this, which is also a proper solution, I did not measure the time, it took me to write that.
name = cgiGetValue (cgi, "name");
if (!name) name = SOME_DEFAULT;
If you allow for GCC extensions, it looks like this: name = cgiGetValue (cgi, "name") ?: SOME_DEFAULT;That would fail on a user supplying a multiple where you don't expect.
> If multiple fields are used (i.e. a variable that may contain several values) the value returned contains all these values concatenated together with a newline character as separator.
Re:30 Years of <Br> Tags
by 1718627440 on Wednesday December 17, 2025 @03:21AM
(#46299481)
Why? The actual implementation of cgiGetValue I am talking about does exactly that:
> concatenated together with a newline character
In GPās defense, there is no standard behavior in the spec for handling repeated GET query parameters. Therefore any implementation-defined behavior is reasonable, including: keeping only the first, keeping only the last, keeping one at random, allowing access to all of them, concatenating them all with a separator, discarding the entire thing, etc.