Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ static void cursor_position(JSON_ParserState *state, long *line_out, long *colum

while (cursor >= state->start) {
if (*cursor-- == '\n') {
line++;
break;
}
column++;
Expand Down
11 changes: 10 additions & 1 deletion test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def test_parse_error_incomplete_hash
end

def test_parse_error_snippet
omit "C ext only test" unless RUBY_ENGINE == "ruby"
omit "JRuby errors don't contain positions" unless RUBY_ENGINE == "ruby"

error = assert_raise(JSON::ParserError) { JSON.parse("あああああああああああああああああああああああ") }
assert_equal "unexpected character: 'ああああああああああ' at line 1 column 1", error.message
Expand All @@ -875,6 +875,15 @@ def test_parse_error_snippet

error = assert_raise(JSON::ParserError) { JSON.parse("abcあああああああああああああああああああああああ") }
assert_equal "unexpected character: 'abcあああああああああ' at line 1 column 1", error.message

error = assert_raise(JSON::ParserError) { JSON.parse("[1,\n@") }
assert_equal "unexpected character: '@' at line 2 column 1", error.message

error = assert_raise(JSON::ParserError) { JSON.parse("[\n 1,\n @\n]") }
assert_equal "unexpected character: '@' at line 3 column 3", error.message

error = assert_raise(JSON::ParserError) { JSON.parse("@") }
assert_equal "unexpected character: '@' at line 1 column 1", error.message
end

def test_parse_leading_slash
Expand Down
Loading