fix: format + flag now correctly overrides space flag - #1089
Merged
stephenamar-db merged 1 commit intoJul 28, 2026
Merged
Conversation
Motivation:
When both + and space flags are present in std.format (e.g. "%+ d"),
the + flag must override the space flag per Python/C printf semantics.
sjsonnet had the condition order reversed, causing space to win.
Modification:
Swap the condition order in Format.scala so signCharacter (+) is
checked before blankBeforePositive (space).
Result:
std.format("%+ d", [42]) now produces "+42" instead of " 42",
matching go-jsonnet, jrsonnet, Python, and C99 §7.19.6.1.
He-Pin
force-pushed
the
fix/format-plus-space-flag-priority
branch
from
July 27, 2026 17:25
67d696f to
0219502
Compare
stephenamar-db
approved these changes
Jul 28, 2026
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
+and space flags appear instd.format(e.g."%+ d"), the+flag must override the space flag. sjsonnet had the condition order reversed, causing space to win.Behavior comparison
std.format("%+ d", [42])" 42"❌"+42"✅"+42""+42"'+42'std.format("% +d", [42])" 42"❌"+42"✅"+42""+42"'+42'std.format("%+ f", [3.14])" 3.140000"❌"+3.140000"✅"+3.140000""+3.140000"'+3.140000'std.format("%+ d", [0])" 0"❌"+0"✅"+0""+0"'+0'std.format("% d", [42])" 42"✅" 42"✅" 42"" 42"' 42'std.format("%+d", [42])"+42"✅"+42"✅"+42""+42"'+42'std.format("%+ d", [-42])"-42"✅"-42"✅"-42""-42"'-42'Specification reference
+and space flags both appear, the space flag is ignored."%formatting:'%+ d' % 42→'+42'%"Test plan
./mill 'sjsonnet.jvm[2.13.18]'.test— all tests pass, no regressions