Skip to content

std.splitLimit negative maxsplits differs from Jsonnet 0.22.0 #803

@He-Pin

Description

@He-Pin

Summary

During the stdlib 1:1 audit, std.splitLimit / std.splitLimitR were found to differ for negative maxsplits values other than -1.

Official C++ Jsonnet v0.22.0 treats negative integer maxsplits as unlimited splitting. sjsonnet currently rejects values below -1.

Evidence

Environment:

  • official C++ Jsonnet: Jsonnet commandline interpreter v0.22.0
  • go-jsonnet: Jsonnet commandline interpreter (Go implementation) v0.22.0
  • jrsonnet: source-built jrsonnet 0.5.0-pre98, commit 80cd36abd868507312e2cc2c78cb0f55a684c620
  • sjsonnet: PR fix: Align stdlib 1:1 edge semantics #800 worktree assembly
expression official Jsonnet 0.22.0 go-jsonnet 0.22.0 source-built jrsonnet sjsonnet PR #800
std.splitLimit("a,b,c", ",", -1) ["a","b","c"] ["a","b","c"] ["a","b","c"] ["a","b","c"]
std.splitLimit("a,b,c", ",", -2) ["a","b","c"] error error error
std.splitLimit("a,b,c", ",", -0.5) ["a,b,c"] error error ["a,b,c"]
std.splitLimit("a,b,c", ",", 0.5) ["a,b,c"] error error ["a,b,c"]
std.splitLimit("a,b,c", ",", 1.5) ["a","b,c"] error error ["a","b,c"]
std.splitLimitR("a,b,c", ",", -2) ["a","b","c"] error error error

Notes

This edge is subtle:

  • official C++ Jsonnet's observed CLI behavior treats negative integer limits as unlimited;
  • go-jsonnet and jrsonnet reject values below -1;
  • sjsonnet currently matches go/jrsonnet for -2, but matches official for fractional values that truncate to 0 or 1.

Direction

For strict official CLI compatibility, sjsonnet should treat negative integer maxsplits values as unlimited, not only -1, while preserving the current fractional truncation behavior that already matches official for -0.5, 0.5, and 1.5.

Add direction tests for both splitLimit and splitLimitR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions