fix(printf): diagnose missing/invalid format characters; support %S/%C - #684
Merged
Conversation
Bad conversion specs were echoed literally with status 0 (issue #681). Match bash: - a conversion that runs off the end of the format -- a bare `%', a dangling `%5', or trailing length modifiers like `%z' / `%lz' -- reports ``%SPEC': missing format character' with the whole spec - an unknown conversion character reports ``C': invalid format character' (`%y' used to infinite-loop old printfs) - both stop processing with status 1 while the accumulated output is still written (`ab%Mcd' prints `ab') - an unclosed `%(' keeps bash's literal-echo behavior - %S and %C are recognized as bash's synonyms for the wide %ls / %lc in a multibyte locale (character-counting width/precision), plain %s / %c otherwise Verified byte-identical with bash 5.3.15 on 20 cases; printf.tests scoreboard 49 -> 36, builtins/errors/varenv/heredoc hold at 0. Closes #681
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
Fixes #681. Bad conversion specs were echoed literally with status 0; they now match bash:
%, dangling%5, trailing length modifiers%z/%h/%L/%lz) →%SPEC': missing format characterwith the whole spec quotedC': invalid format character(%yfamously infinite-looped ancient printfs)printf 'ab%Mcd' xprintsab)%(keeps bash's literal-echo behavior%S/%Crecognized as bash's synonyms for wide%ls/%lcin multibyte locales (character-counting width/precision), plain%s/%cotherwiseVerification
Byte-identical vs reference bash 5.3.15 on 20 cases, including all dangling-modifier forms, mid-format stop,
%Swidth/precision in UTF-8, and no-regression checks on%%,%ld,%lld,%Lf,%5.2d. printf.tests scoreboard 49 → 36; builtins/errors/varenv/heredoc hold at 0; smoke passes.Closes #681
🤖 Generated with Claude Code