[php-src] PR #22041: Fix GH-19088: Make sscanf %c read whitespace
| From: | prateekbhujel | Date: | Thu, 14 May 2026 02:01:52 +0000 |
| Subject: | [php-src] PR #22041: Fix GH-19088: Make sscanf %c read whitespace | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36122@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22041
Author: prateekbhujel
Fixes GH-19088.
%c already disables the usual leading whitespace skip, but after that it still reused
the %s scan path, which stops as soon as it sees whitespace. That made
sscanf(' ', '%c%n', ...) assign an empty string and leave the
offset at 0.
Keep %c separate from %s in the scan loop so it consumes the requested
number of characters, including spaces. The same scanner is used by fscanf(), so the
existing %c expectations there are updated as well.
Tests run:
```
sapi/cli/php run-tests.php -q ext/standard/tests/strings/gh19088.phpt
sapi/cli/php run-tests.php -q ext/standard/tests/strings/gh19088.phpt
ext/standard/tests/strings/sscanf_basic4.phpt ext/standard/tests/strings/bug21730.phpt
ext/standard/tests/file/fscanf_variation20.phpt ext/standard/tests/file/fscanf_variation21.phpt
ext/standard/tests/file/fscanf_variation22.phpt ext/standard/tests/file/fscanf_variation23.phpt
ext/standard/tests/file/fscanf_variation24.phpt ext/standard/tests/file/fscanf_variation25.phpt
ext/standard/tests/file/fscanf_variation26.phpt
git diff --check
```