Skip to content

fix: Align stdlib edge cases with Jsonnet#794

Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:fix-filtermap-lazy-semantics
Open

fix: Align stdlib edge cases with Jsonnet#794
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:fix-filtermap-lazy-semantics

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin commented Apr 26, 2026

Motivation:
Several stdlib functions diverged from official Jsonnet on lazy callback evaluation, ASCII-only string helpers, string set membership, numeric parsing beyond Long range, and signed zero handling.

Modification:

  • Preserve std.filterMap callback laziness and avoid evaluating elements that the callbacks do not force.
  • Reject non-string results from std.flatMap on strings, including null.
  • Make std.asciiUpper, std.asciiLower, and std.equalsIgnoreCase ASCII-only instead of JVM Unicode case folding.
  • Allow std.setMember to operate on string sets with set validation enabled.
  • Parse std.parseInt, std.parseOctal, and std.parseHex into Jsonnet number semantics instead of Long-bounded integers.
  • Normalize std.sign(-0) to numeric zero.
  • Add focused utest coverage plus new direction tests under new_test_suite.

Result:
sjsonnet now matches official Jsonnet v0.22.0 for these stdlib edge cases while preserving performance-oriented implementations for hot paths.

Validation:

  • jsonnet --version -> Jsonnet commandline interpreter v0.22.0
  • Official jsonnet on new success direction tests returned true: filter_map_laziness, ascii_case_non_ascii, equals_ignore_case_ascii, set_member_string, parse_large_numbers, sign_negative_zero.
  • Official jsonnet on error.std.flatmap_string_null.jsonnet errors with std.flatMap on strings, provided function must return a string, got null.
  • ./mill --no-server sjsonnet.jvm[3.3.7].test -> SUCCESS
  • ./mill --no-server sjsonnet.jvm[3.3.7].checkFormat -> SUCCESS
  • git diff --check and git diff --cached --check -> clean

Notes:

Motivation:
Several stdlib functions diverged from official Jsonnet on edge cases around lazy callbacks, ASCII-only string helpers, string set membership, parsing beyond Long range, and signed zero.

Modification:
Preserve lazy filterMap callback arguments, reject non-string string-flatMap results, implement ASCII-only case conversion and equalsIgnoreCase, allow string setMember validation, parse integers into Jsonnet number semantics, normalize std.sign(-0), and add directional tests validated against jsonnet v0.22.0.

Result:
sjsonnet matches official Jsonnet on these stdlib edge cases while avoiding unnecessary filterMap element evaluation and Unicode case-mapping overhead.
@He-Pin
Copy link
Copy Markdown
Contributor Author

He-Pin commented Apr 26, 2026

Additional audit note from the four-implementation matrix:

expression official Jsonnet 0.22.0 go-jsonnet 0.22.0 source-built jrsonnet 0.5.0-pre98 (80cd36a) sjsonnet PR #800 worktree
std.parseInt("+1") error 1 error 1
std.parseHex("+10") error error error 16

The PR #794 parse implementation appears to cover this because it routes parsing through parseNat and only special-cases -, matching official std.jsonnet:

if str[0] == '-' then
  -parse_nat(str[1:], 10)
else
  parse_nat(str, 10)

So this is not a new issue if #794 lands, but it is worth keeping as an explicit direction test because go-jsonnet accepts std.parseInt("+1") while official Jsonnet and jrsonnet reject it.

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.

1 participant