ostap / comp

a tool for querying files in various formats
MIT License
43 stars 2 forks source link

Invalid JSON response if data contains control or non-printable characters. #29

Closed julochrobak closed 10 years ago

julochrobak commented 10 years ago

The JSON response is created with a help of strconv.Quote function. From the golang documentation, the Quote returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by IsPrint. However, the "\xFF" cannot be used in JSON string literals.

Here is an example:

$ bin/comp '{id: "^A"}'
{ "id": "\x01" }
$ bin/comp '{id: "^A"}' | bin/comp -f @json 'in'
failed to load in.json: invalid character 'x' in string escape code