191 Commits

Author SHA1 Message Date
John Bartholomew
567b61ac4a release: v0.22.0 2026-03-24 15:55:53 +00:00
Florian
502106b2a2 fix: add missing linter golden files for cyclic tests 2026-03-23 20:36:15 +00:00
Florian
033195b173 fix: add stack frame accounting to manifest builtins
builtinManifestJSONEx, builtinManifestYamlDoc and builtinManifestTomlEx
use native Go recursion that bypasses MaxStack. A self-referential
object like {a: $} causes unbounded memory allocation until OOM.

Add i.newCall() at the top of each recursive closure, matching the
pattern used by manifestJSON in interpreter.go.
2026-03-23 20:36:15 +00:00
John Bartholomew
b5ef4cd9c4 release: prepare to release v0.22.0-rc1 2026-03-12 12:26:51 +00:00
John Bartholomew
4e0952795e improve handling of YAML document streams in std.parseYaml
This doesn't make them fully correct, in particular directives sections
(e.g., "%YAML 1.2" directive before a document start marker) are not
handled correctly, but they weren't handled correctly before, either.

It also doesn't recognise or try to do anything about document end
markers (`...`).

This fix does allow scalar documents to be on the same line as the
document start tag which is valid per examples in the YAML spec,
see for example https://yaml.org/spec/1.2.1/#id2760844
(YAML 1.2.1 spec, section 2.3 Scalars)

It also matches the C++ jsonnet output for std.parseYaml("42\n---"),
which is a stream of two documents, a scalar and then an empty document
(where the empty document is interpreted as JSON null)
2026-03-08 13:43:04 +00:00
John Bartholomew
80e9deb4d8 restrict bitwise operations argument range to the safe-integer range
Fixes #858.

This is intended to match the restriction added in C++ Jsonnet in
https://github.com/google/jsonnet/pull/1217
and updated in https://github.com/google/jsonnet/pull/1240
2026-03-05 13:39:10 +00:00
He-Pin
2b6894d81e chore: update stdlib_smoke_test.jsonnet with with float closing test 2026-03-01 00:01:17 +08:00
John Bartholomew
1ef3750d6c simplify and clean up formatter_test
There were various bits of dead code and easily simplified things.
2026-02-24 18:28:21 +00:00
John Bartholomew
7792b06ec6 update cpp-jsonnet to (unreleased) e4981ff1199f24fc6d3110311196aebfeca76eca
Also fix update_cpp_jsonnet.sh because the bazel/ directory was removed.

Update test goldens (due to line shifts caused by standard library changes)
2026-02-19 21:42:13 +00:00
John Bartholomew
fb23cdf1c0 fix: desugar the index expression of a super[e]
Fixes https://github.com/google/go-jsonnet/issues/679
2026-02-18 17:16:35 +00:00
John Bartholomew
6c08b4414a import golang golden overrides from cpp-jsonnet
All the go-jsonnet golden output overrides should be kept here in
the go-jsonnet repo. The older override mechanism (in which the
cpp-jsonnet repo has golden files for Golang ending in .golang)
will be removed.
2026-02-09 01:46:36 +00:00
John Bartholomew
0d99c17d4b feat: add flag --no-trailing-newline to prevent adding the trailing newline on outputs
For https://github.com/google/go-jsonnet/issues/518 to allow users to
keep current behaviour for --string --multi, which on go-jsonnet emitted
output without adding an extra newline.

--no-trailing-newline works with all modes except --yaml-stream.
To avoid confusion, the CLI explicitly rejects the combination of both
flags used together.
2026-02-02 23:55:26 +00:00
Thomas Neidhart
9635d56406 fix: return null if the provided string to parseYaml did not yield any result 2026-01-30 22:38:41 +00:00
Thomas Neidhart
2629204f7c
fix: handle negative range by returning an empty array 2026-01-30 15:54:40 +01:00
John Bartholomew
8d4b3b72ab reimplement builtinObjectRemoveKey to support inheritance
This follows the same pattern as I used for the C++ implementation.
Flattening the object is probably also possible, but I think it would
involve binding references to 'super' iff they are satisfied by fields
in existing ancestors and leaving them unbound if they're unsatisfied
so that they can be late-bound by extending the output object.

That seems at least as complicated as defining a new form of
uncachedObject to represent a key-removal operation.

For https://github.com/google/go-jsonnet/issues/830
2026-01-29 20:12:46 +00:00
David
c01b909cf1 fix: do not mutate std.removeAt parameters
Resolves google/go-jsonnet#807
2026-01-27 22:21:38 +00:00
John Bartholomew
a44ee9452f add end to end tests for number literals with underscore digit separators 2026-01-27 18:43:46 +00:00
John Bartholomew
2752a4418e add trailing newline in testdata/builtinIsNull{,2}.jsonnet 2026-01-26 19:35:00 +00:00
Shreyas Dudul
c948b61e94 feat: implement std.isNull 2026-01-26 19:33:59 +00:00
John Bartholomew
693c3e3f70 update bazel deps and cpp-jsonnet to commit bd1f67e305
This is not a named release, but pulls in a stdlib change and also
updates to Bazel build needed for Bazel 9 compatibility.
2026-01-26 18:07:48 +00:00
John Bartholomew
10aef6a96c chore: add test cases for std.manifestYamlDoc error reporting 2025-06-19 15:46:07 +01:00
John Bartholomew
67968688d9 release: prepare to release v0.21.0 2025-05-07 16:12:02 +01:00
Rudo Thomas
1c79f577ba fix: Fix error messages when a comprehension iterates over a non-array.
Problems:
 - When iterating over an empty string in a list comprehension, the
   result is an empty string. This is a bug, it should be an error.
 - When iterating over a non-empty string in a list comprehension, the
   expected and unexpected types in the error message are swapped.
 - Error messages mention "std.flatMap" when object/list comprehensions
   would iterate over a value that is neither array nor string.

```
$ jsonnet --version
Jsonnet commandline interpreter (Go implementation) v0.21.0-rc2
$ jsonnet -e '[a for a in ""]'
""
$ jsonnet -e '[a for a in "b"]'
RUNTIME ERROR: Unexpected type array, expected string
	<cmdline>:1:1-17
	During evaluation
$ jsonnet -e '{[a]: 1 for a in 2}'
RUNTIME ERROR: std.flatMap second param must be array / string, got number
	<cmdline>:1:1-20
	<cmdline>:1:1-20
	During evaluation
$ jsonnet -e '[a for a in 1]'
RUNTIME ERROR: std.flatMap second param must be array / string, got number
	<cmdline>:1:1-15
	During evaluation
```

FWIW, the C++ implementation does not have any of these problems. It
gives:
```
RUNTIME ERROR: In comprehension, can only iterate over array.
```

In the Go implementation comprehensions are desugared to a call to
std.flatMap which does accept a string in the "arr" parameter.

The fix: Desugar comprehensions to a call to a new hidden builtin which
only accepts arrays.
2025-03-21 16:37:59 +00:00
John Bartholomew
2a3f4afd6a release: prepare to release v0.21.0-rc2 2025-03-12 23:42:07 +00:00
John Bartholomew
52bb10f003 feat: add testdata coverage for minArray/maxArray onEmpty error 2025-03-11 00:45:58 +00:00
Eduardo Sánchez Muñoz
6a15a2f3fc fix: output original value from array in std.minArray and std.maxArray instead of result of keyF 2025-03-10 23:28:39 +00:00
John Bartholomew
5b5bcd566a release: prepare to release v0.21.0-rc1
This updates embedded version numbers, and also updates the
C++ jsonnet dependency to the published v0.21.0-rc1 (source release).
2025-02-22 23:18:43 +00:00
Tim Vergenz
e6f64e89f1
feat: add |||- chomped text block syntax (#773)
Resolves google/jsonnet#289

Companion PR to google/jsonnet#1175
2025-01-20 21:45:15 +00:00
John Bartholomew
74c8d09d4a feat: update cpp-jsonnet and stdlib to latest (unreleased)
This includes the stdlib additions in
https://github.com/google/jsonnet/pull/1187

Also updates golden files for go-jsonnet tests; the changes
to the goldens are mostly changes to error locations from
the standard library.
2025-01-18 17:12:28 +00:00
Thomas Neidhart
e0c6a9ed6f
Fix linter: using a local in an assertion. (#723) 2024-06-10 21:28:17 +01:00
Marko Mikulicic
94a40b2991
Fix field visibility in objectHas for extended objects (#737) 2024-06-10 21:26:12 +01:00
Johannes Gräger
dec1aa2be3
feat: Go implementation for manifestYamlDoc and escapeStringJson (#742)
* Builtins for escapeStringJson and manifestYamlDoc

* Benchmark and tests
2024-06-09 19:27:15 +01:00
itchyny
fa70aa4711
feat: implement std.splitLimitR (#745) 2024-06-09 19:25:22 +01:00
zephyros-dev
fed90cd9cd
fix: add std.objectKeysValues to jsonnet-lint (#706) 2023-06-26 20:40:39 +01:00
Jayme Bird
5fb0b0b578
feat: add std reverse linter (#709)
* feat: add std.reverse to linter

* feat: add linter test case

* feat: fix linter golden test data
2023-06-13 20:15:23 +01:00
Rohit Jangid
2a7260d60c
feat: Add more math functions (#702)
Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-06-13 20:14:26 +01:00
Deep Goel
572c054137
feat: implement std.avg (#700)
* feat: implement std.avg
2023-06-13 17:42:05 +01:00
Rohit Jangid
aece6e9b90
feat: add more crypto functions (#699)
* feat: add more crypto functions
2023-06-13 17:18:02 +01:00
Tejesh Raut
fae841124f
Implement std.trim for string (#684)
* Implement std.trim for string
2023-06-13 13:05:28 +01:00
Deep Goel
7edd5d373b
feat: implement std.maxArray (#696) 2023-05-25 13:45:24 +01:00
Rohit Jangid
4bb6e388b7
feat: implement std.equalsIgnoreCase (#692) 2023-05-25 13:32:39 +01:00
Rohit Jangid
25d3372c98
feat: implement std.remove and std.removeAt (#689)
* feat: implement std.remove and std.removeAt

* Update builtins.go

---------

Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-05-25 13:32:21 +01:00
Rohit Jangid
3c7c0cbac8
feat: implement objectRemoveKey (#686) 2023-05-25 12:55:30 +01:00
Yuki Yugui Sonoda
868d9c6f11
Resolves a false-positive detection of multi-doc YAML streams (#693)
Fixes #673.
2023-05-03 19:37:04 +01:00
Deep Goel
9c0b362ba7
feat: implement std.minArray (#685)
* feat: implement std.minArray
2023-05-03 19:13:56 +01:00
Rohit Jangid
76e4fc2221
feat: implement std.contains (#691) 2023-05-03 19:06:07 +01:00
Dave Cunningham
7903819abf
Bump version to 0.20.0 (#688) 2023-04-17 20:44:57 +01:00
Dave Cunningham
5afe130669 fix newline issue breaking test 2023-04-13 15:33:24 +01:00
Rohit Jangid
18377e6f9f
Add std.round function in standard library. (#683)
Co-authored-by: Dave Cunningham <sparkprime@gmail.com>
2023-04-13 15:32:54 +01:00
Dave Cunningham
b0ff20a87c fix tests 2023-04-13 15:28:29 +01:00