Skip to content

Align string member empty needle semantics#1084

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/member-empty-string
Open

Align string member empty needle semantics#1084
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/member-empty-string

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

std.member accepts either an array or a string as its first argument. For strings, the official Jsonnet stdlib defines membership through std.findSubstr(x, arr), and std.findSubstr("", "abc") returns an empty array. That means an empty string should not be considered a string member.

sjsonnet's native implementation delegated directly to JVM String.contains, which treats the empty string as contained in every string. This made std.member("abc", "") and std.member("", "") return true, even though the official stdlib-derived semantics return false.

Modification

  • Require the string needle in std.member to be non-empty before calling String.contains.
  • Add regression coverage for empty string needles in string membership.
  • Add array membership coverage to show that std.member([""], "") remains true.

Result

Implementation std.member("abc", "") std.member("", "") std.member([""], "") std.findSubstr("", "abc")
cpp-jsonnet false false true []
go-jsonnet true true true []
jrsonnet false false true []
sjsonnet before this PR true true true []
sjsonnet after this PR false false true []

sjsonnet now matches cpp-jsonnet and jrsonnet for string membership with an empty needle, while preserving normal substring membership and array element membership.

References

@He-Pin He-Pin marked this pull request as draft July 4, 2026 10:16
@He-Pin He-Pin marked this pull request as ready for review July 4, 2026 12:02
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