Skip to content

fix: std.parseInt accepts + prefix like go-jsonnet#1030

Merged
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/format-subnormal-numbers
Jun 24, 2026
Merged

fix: std.parseInt accepts + prefix like go-jsonnet#1030
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/format-subnormal-numbers

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR updates std.parseInt to accept a leading + sign, matching go-jsonnet behavior for decimal integer parsing.

Behavior comparison

Local reference versions used:

  • C++ jsonnet v0.22.0
  • go-jsonnet v0.21.0 and v0.22.0
  • jrsonnet 0.5.0-pre99
Expression C++ jsonnet go-jsonnet jrsonnet sjsonnet before sjsonnet after
std.parseInt("+1") error 1 error error 1
std.parseInt("+0") error 0 error error 0
std.parseInt("+01") error 1 error error 1
std.parseInt("+") error error error error error
std.parseInt("+-1") error error error error error
std.parseInt("-123") -123 -123 -123 -123 -123
std.parseInt("123") 123 123 123 123 123

The intentional compatibility target here is go-jsonnet for plus-prefixed decimal input. C++ jsonnet and jrsonnet currently reject the leading + cases above.

Changes

  • StringModule.scala: handle a leading + sign in std.parseInt
  • parseInt_positive_sign.jsonnet: golden regression coverage for accepted + inputs and unchanged positive/negative baselines

Tests

rtk ./mill 'sjsonnet.jvm[3.3.7]'.test.testOnly sjsonnet.FileTests
rtk git diff --check upstream/master...HEAD

Both passed locally after rebasing onto upstream/master.

@He-Pin He-Pin changed the title fix: std.format %e/%g produce correct output for subnormal numbers fix: std.format subnormal numbers + std.parseInt accepts + prefix Jun 24, 2026
@He-Pin He-Pin force-pushed the fix/format-subnormal-numbers branch from 1d5d985 to e2836ae Compare June 24, 2026 16:00
@He-Pin He-Pin changed the title fix: std.format subnormal numbers + std.parseInt accepts + prefix fix: std.parseInt accepts + prefix like C++ jsonnet and go-jsonnet Jun 24, 2026
CertainLach added a commit to deltarocks/jrsonnet that referenced this pull request Jun 24, 2026
Ref: databricks/sjsonnet#1030
Change-Id: I1e4a88229841d25d9502bff7795c43676a6a6964
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
@stephenamar-db

Copy link
Copy Markdown
Collaborator

do you need the LLM md file in this PR?

@He-Pin He-Pin force-pushed the fix/format-subnormal-numbers branch from afffd2c to 19ee313 Compare June 24, 2026 17:07
@He-Pin

He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@stephenamar-db fixed, and the result is runtime error: "+123" is not a base 10 integer in jrsonnet

Motivation:
go-jsonnet accepts a leading + sign in std.parseInt decimal input, while sjsonnet rejected it despite already handling the negative sign path.

Modification:
Treat a leading + as a sign marker, reject bare + explicitly, and parse the remaining decimal digits using the existing natural-number parser. Add a golden regression test for +123, +0, +007, and unchanged positive/negative baselines.

Result:
std.parseInt now accepts plus-prefixed decimal integers like go-jsonnet without changing existing unsigned or negative parsing behavior.
@He-Pin He-Pin force-pushed the fix/format-subnormal-numbers branch from 19ee313 to 9b1e45c Compare June 24, 2026 17:59
@He-Pin He-Pin changed the title fix: std.parseInt accepts + prefix like C++ jsonnet and go-jsonnet fix: std.parseInt accepts + prefix like go-jsonnet Jun 24, 2026
@stephenamar-db stephenamar-db merged commit ed5162f into databricks:master Jun 24, 2026
5 checks passed
@CertainLach

Copy link
Copy Markdown

result is runtime error: "+123" is not a base 10 integer in jrsonnet

Fixed on master

@He-Pin

He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@CertainLach Thanks

@He-Pin He-Pin deleted the fix/format-subnormal-numbers branch June 24, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants