Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no context for syntax error due to a literal TAB in string #97

Open
trentm opened this issue Nov 27, 2015 · 1 comment
Open

no context for syntax error due to a literal TAB in string #97

trentm opened this issue Nov 27, 2015 · 1 comment

Comments

@trentm
Copy link
Owner

trentm commented Nov 27, 2015

peterg noticed this. If a JSON file has a literal tab character in a string, that is invalid syntax. However, json doesn't give context on the error like it does for other cases.

See for the test files: https://gist.github.com/trentm/45940fadbfaace8d2f50

$ json -nf foo.json
json: error: "foo.json" is not JSON: SyntaxError: Unexpected token

$ json -nf comma.json
json: error: "comma.json" is not JSON: Unexpected ']' at line 1, column 16:
        [{"foo":"bar"},]
        ...............^

Why no context on the error in foo.json that has an illegal literal tab in the string?

@trentm
Copy link
Owner Author

trentm commented Nov 27, 2015

The json_parse from https://github.com/douglascrockford/JSON-js doesn't balk at the literal TAB. I wonder if it should.

$ ./lib/json.js -nf tab.json
XXX getting detail
XXX json_parse: normBuffer="{\"foo\": \"baa\ttab\"}\n"
XXX json_parse no exception
json: error: "tab.json" is not JSON: SyntaxError: Unexpected token
[09:56:39 trentm@danger0:~/tm/json (master)]
$ ./lib/json.js -nf comma.json
XXX getting detail
XXX json_parse: normBuffer="[{\"foo\":\"bar\"},]\n"
XXX json_parse err { name: 'SyntaxError',
  message: 'Unexpected \']\'',
  at: 16,
  text: '[{"foo":"bar"},]\n' }
json: error: "comma.json" is not JSON: Unexpected ']' at line 1, column 16:
        [{"foo":"bar"},]
        ...............^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant