Skip to content
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

ERROR: incorrect string and dict handling #1166

Open
rprtr258 opened this issue Aug 11, 2024 · 1 comment
Open

ERROR: incorrect string and dict handling #1166

rprtr258 opened this issue Aug 11, 2024 · 1 comment

Comments

@rprtr258
Copy link

rprtr258 commented Aug 11, 2024

Using

$ jsonnet --version
Jsonnet commandline interpreter (Go implementation) v0.20.0

with following expression:

"1" {}
// or
["1" {}]

expecting syntax error, comma expected, but got

"1{ }"
// or
[
  "1{ }"
]

Works in playground too.

Found while generated xml from incorrect input that was like

["article" {id: "main", class: "markdown-section", role: "main", tabindex: "-1"}, "text"]

which was handled incorrectly before xml-transform to

[
  "article{\"class\": \"markdown-section\", \"id\": \"main\", \"role\": \"main\", \"tabindex\": \"-1\"}",
  "text"
]

while expected

[
  "article",
  {
    "class": "markdown-section",
    "id": "main",
    "role": "main",
    "tabindex": "-1"
  },
  "text"
]
@johnbartholomew
Copy link
Collaborator

This is a result of two aspects of the language specification:

  1. x + y if one of the arguments is a string is defined to perform string concatenation, converting the other argument to a string if necessary.
  2. x { ... } is defined to expand to x + { ... } as part of desugaring (see the spec for full definition).

I agree it is an unintuitive behaviour in this case. However, fixing it would be a language change that might have unintended effects, so it needs some further design consideration.

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