Live data from Hacker News

I found and fixed a bug in PHP's standard library

miguelxpn.com

1–10 of 33 posts

Re: I found and fixed a bug in PHP's standard library

#3
post #2

Notably, the bugfix made PHP maintainers realize that the header handler had additional behaviors that they did not understand nor had a rationale for, so those behaviors were removed as well: https://github.com/php/php-src/pull/5201

Feels like this could be a case where DRY could fix a bug in one place

Re: I found and fixed a bug in PHP's standard library

#6
post #3
post #2

Notably, the bugfix made PHP maintainers realize that the header handler had additional behaviors that they did not understand nor had a rationale for, so those behaviors were removed as well: https://github.com/php/php-src/pull/5201

Feels like this could be a case where DRY could fix a bug in one place

I was thinking the same so I checked and they removed the duplication:

https://github.com/php/php-src/commit/3d9c02364db62a6d8e2794...

They also fixed the whitespace handling that let something like "RandomHeader: hello host:8080" mistakenly set the flag.

https://github.com/php/php-src/commit/56cdbe63c24b86c2f1d60b...

Re: I found and fixed a bug in PHP's standard library

#7
post #3
post #2

Notably, the bugfix made PHP maintainers realize that the header handler had additional behaviors that they did not understand nor had a rationale for, so those behaviors were removed as well: https://github.com/php/php-src/pull/5201

Feels like this could be a case where DRY could fix a bug in one place

DRY is a good principle, but sometimes I’d rather repeat myself a little bit than build more bug-prone scaffolding to avoid repetition—especially when the repetition isn’t line-for-line identical. Just remember to always cite the repetition in comments.

Re: I found and fixed a bug in PHP's standard library

#8
Looking at lines 460-521 in the modified file (https://github.com/miguelxpn/php-src/blob/f4b2089b642d504be3...), is there not a benefit to `break` out of the while loop in the nested if statements?

Otherwise, it looks like it will call strstr() one extra time, even though you may have already determined that the specific header is present.

Re: I found and fixed a bug in PHP's standard library

#9
post #8

Looking at lines 460-521 in the modified file ( https://github.com/miguelxpn/php-src/blob/f4b2089b642d504be3... ), is there not a benefit to `break` out of the while loop in the nested if statements? Otherwise, it looks like it will call strstr() one extra time, even though you may have already determined that the specific header is present.

Good catch! That's indeed the case. Another commit was made where that piece of code was refactored into a function and it returns 1 in case the header is present so strstr isn't being called an extra time in the current code.

[1] https://github.com/php/php-src/commit/3d9c02364db62a6d8e2794...

Re: I found and fixed a bug in PHP's standard library

#10
post #8

Looking at lines 460-521 in the modified file ( https://github.com/miguelxpn/php-src/blob/f4b2089b642d504be3... ), is there not a benefit to `break` out of the while loop in the nested if statements? Otherwise, it looks like it will call strstr() one extra time, even though you may have already determined that the specific header is present.

Good catch! That's indeed the case. Another commit was made where that piece of code was refactored into a function and it returns 1 in case the header is present so strstr isn't being called an extra time in the current code. [1] https://github.com/php/php-src/commit/3d9c02364db62a6d8e2794...

Ah, much cleaner!
Post reply on HN