Repository navigation
Fix GH-19088: Make sscanf %c read whitespace - #22041
prateekbhujel wants to merge 4 commits into
Conversation
acdb609 to
08ea8fb
Compare
|
@devnexen quick follow-up on this one: the extra |
hakre
left a comment
There was a problem hiding this comment.
can you summarize if/how %c differs now from the original code? (see file comment)
Sure. Previously Now |
Thanks for the detailed clarification – that matches exactly what I expected. The key point is that Given that this is a straightforward bug fix (and not a new feature or intentional behavioral change), it would be great to treat it as such – i.e., target the oldest supported branch where the bug exists, and remove the UPGRADING note (or replace it with a bug‑fix entry in the changelog). That way users on stable versions get the correct behavior too. I mentioned the file comment in Happy to help with any further testing or wording if needed. 😊 |
|
Ah yes, that makes sense. I added the UPGRADING note because the visible result changes, but I agree with your framing here: this is fixing the I’ll remove the UPGRADING note and keep this as a bug fix. For the target branch, I’ll follow whichever oldest supported branch the maintainers want this based on, rather than treating it as master-only. I’ll also cross-check the Tcl code before the next update so the PR text is clear about why this is a porting oversight. Thanks, this helped make the direction much clearer. |
|
That’s a great direction – thanks for taking the time to dig into the Tcl history. One small nuance: @devnexen has a point that any change in visible behavior, even a bug fix, can be a BC break for code that relied on the old (broken) Happy to help with the exact wording if needed. 😊 |
|
Yes, agreed. That is the better balance. I put the UPGRADING note back, but worded it as a correction rather than a new feature:
Pushed that in |
|
Given that this is a bug fix that isn't a security fix, |
|
Understood, that reading makes sense to me. I would rather leave the final branch/base decision to the maintainers here instead of guessing and moving the PR myself. If @devnexen, @Girgias, or @TimWolla confirm that PHP-8.4 is the right target, I can retarget/rebase the PR there and keep the current wording/tests. So for now I will wait for their call. |
|
The contributing guide is pretty clear that bug fixes go to the lowest supported branch and master is for RFCs—I think you're safe to retarget to PHP-8.4. If the maintainers disagree, they'll let us know, but taking the initiative is always appreciated. 😊 |
|
From what I see, @ndossche requested this as a master-only change in the corresponding issue since a change to long-standing behavior that is not obviously buggy is not something folks expect within the the same PHP version - and I would agree with that. I defer to someone else to evaluate the patch itself. |
|
For what it’s worth, the BC impact here is minimal: because the old %c stopped at whitespace, it was effectively unusable for its intended purpose. The fix restores the documented ANSI C behaviour without breaking any reasonable existing code. |
|
Any updates here, or is anything else needed from my side? |
|
This has been the behaviour since PHP 4.3.2: https://3v4l.org/6t26R#veol And while this might be a bug fix, my experience fixing stuff for SPL tells me that people will either be working around this or expecting this, so we will get people complaining we broke something. |
Interesting, PHP 4.3.2 is from a time and major PHP version that is different from ... SPL:
This leaves us with the range you opened up here: User work arounds or expecting this. Please assess that in context of the fix, that is about the original port to PHP from TCL, not the SPL. And very interesting in my eyes, but decide for yourself @Girgias |
|
In case it helps @Girgias (and naturally for others who are interested), some resources:
(refs, please vet the version/release dates independently, I took the TCL version named in the PHP sources) |
d88f22e to
c8f19f4
Compare
|
Thanks @Girgias, that concern is fair. I rebased this on current master now, so the conflicts should be gone and CI is running again. I am keeping this master-only as @TimWolla suggested. My view is still that this corrects the |
Hmm, good point and thinking I probably have barken up the wrong tree previously: Please share your assessment of the risk then in regards to the SPL, which was introduced later. @prateekbhujel |
|
Thanks @hakre, yeah I might have phrased that badly. I do not read the SPL part as being directly related to this code path. I understood @Girgias’ point more as a maintainer experience thing: even when some old behavior looks wrong, if it has existed for a long time, some users may already rely on it or have workarounds around it. So for this PR my risk assessment is not really SPL-specific. The risk is that That is why I think keeping it master-only, with the UPGRADING note, is the safer framing. I still think this corrects the |
You're welcome & all fine - if then it's my Englitsch I'm sure.
Which seems was the concensus already earlier, and the reason to fix on master not on a branch with a number. I'd also not go that far and say the fix is risky: From what I know any workaround involves not using %c so is technically not affected. Perhaps the maintainers could voice what would help them to better assess the risk, because I don't write this in ignorance. E.g. changing the trim default cutset that is actually backwards breaking and with its own risks, and be it only in the toolings in use (refs 3v4l.org). |
|
@hakre Yeah that makes sense. I also do not want to overstate the risk here. My point was mostly that since this behavior has existed for so long, I understand why maintainers may want to be conservative, even if the practical breakage is probably small. |
|
You're a genius in my eyes: it not only makes sense, when thinking conservatively and addressing the SPL as the messenger (the thing it actually is), making out the fix must be in the PHP language in the sscanf() and fscanf() functions only, to address the differences between the PHP standard library and the SPL as both are part of it, but they are different libraries. The SPL retains the implementation defined behaviour under the modernization of PHP: PHP 5 with the introduction of the unified Wow, this reflects the heritage of ANSI C, TCL, PHP 4.3 and later, and last, but not least, the SPL. I really love this bugfix, and it's not only because of the code, thanks for keeping the discussion going @prateekbhujel /cc @Girgias |
I can't make a final call, this is not how decisions are made here. Please send a quick email to internals if other people think it's problematic, if not I'll merge it. |
|
@hakre thank you, that honestly means a lot. I am still learning my way around php-src and internals, so the discussion here helped me understand the framing much better. @Girgias I sent the quick mail to internals now as suggested. I will wait for feedback there, and if there are no objections we can continue from that. |
|
@hakre if you have a moment, could you also share your thoughts in the internals discussion? Your points here about the practical BC risk would be helpful there too. |
|
@Girgias Just following up on this. The internals discussion has been open for about 8 weeks now with no objections or concerns raised: The branch is rebased, mergeable, and all CI checks are green. Let me know if you're good to merge this or if anything else is needed ! |
c8f19f4 to
3b03fbd
Compare
|
@Girgias rebased onto current master after the 8.6 fork and kept the UPGRADING note under 8.7. The 60 scanf tests pass on a fresh debug build; 8 tests need 32-bit, and CI is rerunning. The internals thread still has no replies. Could you take another look when you have time? |
Keep the %c conversion separate from %s so it reads whitespace instead of stopping at it. The %c conversion already suppresses leading whitespace skipping; it also must not treat whitespace as the end of the field.
3b03fbd to
1a18fc8
Compare
Fixes GH-19088.
%cdisables the leading whitespace skip, but still uses the%sscan path, which stops at whitespace. That makessscanf(' ', '%c%n', ...)assign an empty string and leave the offset at 0.Keep
%cseparate from%sso it consumes the requested characters, including whitespace. The same scanner handlesfscanf(), so its existing%cexpectations are updated too.This targets master (PHP 8.7), with an UPGRADING note for the behavior change.
Tested on a fresh PHP 8.7 debug build: 60 scanf tests passed; 8 tests skipped because they require a 32-bit platform.