-
Notifications
You must be signed in to change notification settings - Fork 441
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
text-block ||| fails to allow trailing whitespace before new-line #421
Comments
Thanks for the report, chomping the whitespace after ||| is pretty trivial I think so we should fix this. Note that converting line endings will change the content of the string specified by |||, as described in the spec. So git's auto crlf feature would still affect the generated jsonnet. I was never comfortable about that, but not sure how to fix it. |
I'm aware of that. The only two options seem to either (1) leave line endings as written withing multi-line strings or (2) normalize them to new-lines in all multi-line string and text-blocks. I guess the question I would pose, who would complain if "\r" characters went away in JSON output? Is a "canonical" output of jsonnet input of value, regardless of system line endings? |
I think the best way is to always treat line endings in the same way, i.e. treat CRLF in the source as LF. Ideally at the lexer level. I think line ending convention in the source code should never affect the semantics. User's platform also shouldn't affect the output. EDIT: |
And there is also a slightly evil option of disallowing CRLF in jsonnet completely to avoid confusion. The only downside I see is forcing people to set up git not to do crlf conversion for .jsonnet and .libsonnet files. (As I'm pretty sure all reasonable editors on Windows play nicely with LF endings). |
@sbarzowski I'd also go with (2) as someone who has tried to make sassc output the same on windows and *nix, and has so far failed. For your (evil 3) option, I'd recommend against it. At least in Go, it used to be stricter about certain line endings and BOM options and finally relaxed it. Though it is always easier to relax then to make stricter. |
(2) SGTM It is easy to add some std.unix2dos(||| ... |||) wrapper. Also, we could have a syntax for it like |||d or whatever. YAML already has several flags you can put, including the one referenced in #289 |
Throw an error on negative shifts
From the spec, carriage returns are considered white space.
From the spec:
Critically, the
|||
may be followed by an optional whitespace and then a new-line. As defined by the spec this would allow jsonnet to work with windows or unix line ending styles. However in implementation, both jsonnet and go-jsonnet both require a "\n" right after the "|||". This causes jsonnet files to fail with windows line endings if it contains a "|||" text block.Other jsonnet features work just fine with CRLF line endings, including mutliline "normal" strings.
(This was discovered by a coworker who had git's auto crlf "feature" enabled.)
The text was updated successfully, but these errors were encountered: