antlr / antlr4-lab

A client/server for trying out and learning about ANTLR
MIT License
39 stars 11 forks source link

JsonSerializer: escape error message in tree #54

Closed qligier closed 2 years ago

qligier commented 2 years ago

Error messages are injected unescaped in the tree (result.tree.kids[].error). If there's a forbidden character, the JSON response becomes invalid. It happens by example if a quoted string is unmatched by the parser

For example:

{
  "result": {
    "tree": {
      "kids": [
        {
          "error": ""string""
        }
      ]
   }
}
parrt commented 2 years ago

Ah! I wonder if it is what is causing https://github.com/antlr/antlr4-lab/issues/51 Can you check? Then we can close as part of the same PR.

qligier commented 2 years ago

It seems so, but it's quite hard to debug a 10 Mo JSON response. The more complete patch here would be to use JsonWriter or Gson to safely create the JSON representation.

parrt commented 2 years ago

closing in favor of #57