From 0219502684b8b22c017928700cfdb1f44501ddb1 Mon Sep 17 00:00:00 2001 From: He-Pin Date: Tue, 28 Jul 2026 01:22:38 +0800 Subject: [PATCH] fix: format + flag now correctly overrides space flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- sjsonnet/src/sjsonnet/Format.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sjsonnet/src/sjsonnet/Format.scala b/sjsonnet/src/sjsonnet/Format.scala index 77377dac..a1869e02 100644 --- a/sjsonnet/src/sjsonnet/Format.scala +++ b/sjsonnet/src/sjsonnet/Format.scala @@ -282,8 +282,8 @@ object Format { signedConversion: Boolean): String = { val lhs2 = - if (signedConversion && formatted.blankBeforePositive) " " + lhs - else if (signedConversion && formatted.signCharacter) "+" + lhs + if (signedConversion && formatted.signCharacter) "+" + lhs + else if (signedConversion && formatted.blankBeforePositive) " " + lhs else lhs val missingWidth = formatted.widthOr(-1) - lhs2.length - mhs.length - rhs.length