apiaryio / drafter

API Blueprint Parser (C++)
https://apiblueprint.org/
MIT License
302 stars 54 forks source link

`"` in JSON values are not escaped correctly #719

Closed kylef closed 5 years ago

kylef commented 5 years ago

Given the following API Blueprint, with an MSON property href":

# API Name

## GET /

+ Response 200 (application/json)
    + Attributes
        + `href"`

The final parse result contains a JSON String:

"{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"href\"\": {\n      \"type\": \"string\"\n    }\n  }\n}"

Note the " is not correctly escaped (\"href\"\") it should be escaped an extra time inside the key quotes.

$ ./bin/drafter dd.apib -f json | jq .content[0].content[0].content[0].content[0].content[1].content[2].content
"{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"href\"\": {\n      \"type\": \"string\"\n    }\n  }\n}"

$ ./bin/drafter dd.apib -f json | jq .content[0].content[0].content[0].content[0].content[1].content[2].content -r
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "href"": {
      "type": "string"
    }
  }
}

$ ./bin/drafter dd.apib -f json | jq .content[0].content[0].content[0].content[0].content[1].content[2].content -r | jq
parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 6, column 7