jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
63 stars 12 forks source link

Issue with curly braces in default #96

Closed alekseyg closed 4 months ago

alekseyg commented 4 months ago

It appears that the default gets mangled when it contains curly braces. For example, I have this schema:

{
  "type":"object",
  "properties":{
    "message":{
      "type":"object",
      "properties":{
        "heading":{
          "type":"string",
          "default":"✨ A message from %{whom}: ✨"
        },
        "organizer":{
          "type":"string",
          "default":"the organizer"
        },
        "content":{
          "type":"string",
          "default":"[Message to your donors]"
        }
      }
    }
  }
}

But when I type out the key for message.heading and the default gets populated, it looks like this:

{
  "message": {
    "heading": "✨ A message from %{whom\: ✨}"
  }
}

A backslash is inserted where the closing curly bracket should be and the curly bracket moves to the end of the string. It's also invalid JSON. I have more values like this with and without emoji, and the result is the same.

alekseyg commented 4 months ago

After playing around with it a little more it appears that it only mangles the first one. Here's an example with multiple curly braces.

Default in schema:

"You made a %{amount} donation on %{date} to %{beneficiary}%{via}."

Mangled value inserted:

"You made a %{amount\ donation on %{date} to %{beneficiary}%{via}.}"
imolorhe commented 4 months ago

I can reproduce the issue. It looks like an issue upstream in codemirror.

acao commented 4 months ago

@alekseyg can you let us know if upgrading your @codemirror/autocomplete version and upgrading to the latest release of our library resolve this issue?

alekseyg commented 4 months ago

@acao Yes! That fixed it. Thank you!