Repository navigation
Format: fixes substring with an end index outside of the string - #2695
Merged
CarterLi merged 1 commit intoOct 31, 2026
Merged
Conversation
Member
|
Conflict |
`{1~20,30}` printed the placeholder as is, because the `,end` part was only
checked when the start index was inside the string. `{1~20}` printed nothing.
Parse and check the whole range first, so that a valid range that lies outside
of the string gives an empty result.
arxhr007
force-pushed
the
fix/format-substring-out-of-range
branch
from
October 31, 2026 14:36
d0f7ded to
7f2faa7
Compare
Contributor
Author
|
Rebased onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A valid substring placeholder with an end index,
{1~start,end}, is printed as is when the start index is outside of the string. The same placeholder without the end index prints nothing, and so do{1~10,10}and{1~10,5}, which are covered by the existing tests.With
12345 67890(11 characters):{1~20}{1~11,12}{1~11,12}{1~20,30}{1~20,30}{1~-50,3}{1~-50,3}{1~-50,-1}{1~-50,-1}The cause is that the
,endpart was only parsed insideif (start >= 0 && start < length). When the start was outside, the parser pointer stayed on the,, and the check for trailing characters then took the valid placeholder for an invalid one. The existing tests for invalid syntax ({1~-,1},{1~0,,1},{1~0,1,}and so on) still print the placeholder as is.Related issue (required for new logos for new distros)
Not a logo. No issue, it is a small fix in the same code as #2669.
Changes
src/common/impl/format.c: parse the optional end index first and check the whole range before using it. A valid range outside of the string now gives an empty result.tests/format.c: four cases for a start index outside of the string with an end index. The first fails on the old code.CHANGELOG.md: bugfix entry.Screenshots
Not a visual change.
Checklist
Built with
-DBUILD_TESTS=On -DENABLE_ASAN=Onand-fsanitize=undefined; all 19 tests pass.