Repository navigation
fix: insert zero padding after sign and prefix in string/base/format-interpolate - #16539
Open
rajanpanth wants to merge 1 commit into
Open
rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
…-interpolate` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@Planeshifter Mind taking a look at these changes since you were the one which originally added this functionality? |
This branch has not been deployed
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.
Description
This pull request:
+orsign and after a0x/0Xprefix instring/base/format-interpolate(and thusstring/format). Previously, only a leading-was moved in front of the zeros, so the zeros landed in front of the sign or the prefix.precisionon the left. Previously, the-flag (left-justify) also flipped the precision padding to the right, which changed the value:format( '%-.5d', 10 )returned'10000'. In C,-only affects how the result is padded to the field width.printf)%+05d4200+42+0042% 05d4200 420042%#08x25500000xff0x0000ff%+08.3f3.1415900+3.142+003.142%-.5d101000000010%-8.3d-7-700-007Related Issues
None.
Questions
No.
Other
test/test.format_integer.jsasserted the old behavior ({ 'precision': 5, 'padRight': true }with10returned'10000'). I updated its expected value to'00010', which is what C'sprintf( "%-.5d", 10 )produces. All other existing tests pass unchanged.zeroPaddirectly with sign and hexadecimal prefixes. The newtest.jstests fail ondevelop(8 assertions), as do the newtest.zero_pad.jstests (5 assertions).%operator, which matches C for these cases.%ginstring/base/format-interpolate#16538 (%g), which touchesformat_double.jsonly.string/base/format-interpolateandstring/formatdirectly with Node.js andtapeon Windows (asmakewas not available in my environment); I did not run the full repository lint pipeline locally.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written with the help of Claude Code, which found the issue, drafted the implementation change and tests, and checked the results against C's
printfsemantics. I reviewed the changes and the test results before submitting.@stdlib-js/reviewers
🤖 Generated with Claude Code