Skip to content

String slicing with negative indices throws an error #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
juliajohannesen opened this issue Feb 27, 2025 · 2 comments
Closed

String slicing with negative indices throws an error #1216

juliajohannesen opened this issue Feb 27, 2025 · 2 comments

Comments

@juliajohannesen
Copy link

juliajohannesen commented Feb 27, 2025

Slicing a string with a negative index, results in an error:

"foo"[1:-1]
RUNTIME ERROR: got [1:-1:1] but negative index, end, and steps are not supported
	std.jsonnet:(220:5)-(234:66)	function <anonymous>
	<stdin>:1:1-12	

Compare this to both go-jsonnet and jrsonnet, which result in the following:

"foo"[1:-1]
"o"

jsonnet --version output (for the failing implementation):

Jsonnet commandline interpreter v0.20.0
@johnbartholomew
Copy link
Collaborator

Thanks for the report, however version 0.20.0 does not support negative slice indexes. It was added in #1093 and is included in the v0.21.0-rc1 release candidate.

@juliajohannesen
Copy link
Author

Ah, gotcha! Thanks!

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

No branches or pull requests

2 participants