google/jsonnet

jsonnet fmt --string-style s does not escape single quotes in strings

Closed this issue · 1 comments

brbbs commented

jsonnet fmt --string-style s (the single quote option) creates invalid jsonnet if a string has a single quote inside it.

Given a foo.jsonnet:

{
  foo: "'bar'",
  bar: '\'baz\'',
}

jsonnet fmt --string-style s produces:

$ jsonnet fmt --string-style s foo.jsonnet | tee foo.jsonnet
{
  foo: ''bar'',
  bar: ''baz'',
}

Which of course is invalid jsonnet:

$ jsonnet foo.jsonnet
STATIC ERROR: foo.jsonnet:2:10-12: Expected a comma before next field.

Sorry for the slow response, output is now:

$ jsonnet fmt --string-style s foo.jsonnet 
{
  foo: "'bar'",
  bar: "'baz'",
}