Skip to content

Commit

Permalink
Fix the remaining error message asserting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 16, 2025
1 parent 0aabbc5 commit ea0db6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,15 @@ static VALUE json_parse_any(JSON_ParserState *state)
return PUSH(Qnil);
}

raise_parse_error("unexpected character: %s", state->cursor);
raise_parse_error("unexpected token at '%s'", state->cursor);
break;
case 't':
if ((state->end - state->cursor >= 4) && (memcmp(state->cursor, "true", 4) == 0)) {
state->cursor += 4;
return PUSH(Qtrue);
}

raise_parse_error("unexpected character: %s", state->cursor);
raise_parse_error("unexpected token at '%s'", state->cursor);
break;
case 'f':
// Note: memcmp with a small power of two compile to an integer comparison
Expand All @@ -908,7 +908,7 @@ static VALUE json_parse_any(JSON_ParserState *state)
return PUSH(Qfalse);
}

raise_parse_error("unexpected character", state->cursor);
raise_parse_error("unexpected token at '%s'", state->cursor);
break;
case 'N':
// Note: memcmp with a small power of two compile to an integer comparison
Expand All @@ -917,21 +917,25 @@ static VALUE json_parse_any(JSON_ParserState *state)
return PUSH(CNaN);
}

raise_parse_error("unexpected character: %s", state->cursor);
raise_parse_error("unexpected token at '%s'", state->cursor);
break;
case 'I':
if (state->config->allow_nan && (state->end - state->cursor >= 8) && (memcmp(state->cursor, "Infinity", 8) == 0)) {
state->cursor += 8;
return PUSH(CInfinity);
}

raise_parse_error("unexpected character", state->cursor);
raise_parse_error("unexpected token at '%s'", state->cursor);
break;
case '-':
// Note: memcmp with a small power of two compile to an integer comparison
if (state->config->allow_nan && (state->end - state->cursor >= 9) && (memcmp(state->cursor + 1, "Infinity", 8) == 0)) {
state->cursor += 9;
return PUSH(CMinusInfinity);
if ((state->end - state->cursor >= 9) && (memcmp(state->cursor + 1, "Infinity", 8) == 0)) {
if (state->config->allow_nan) {
state->cursor += 9;
return PUSH(CMinusInfinity);
} else {
raise_parse_error("unexpected token at '%s'", state->cursor);
}
}
// Fallthrough
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {
Expand Down
2 changes: 1 addition & 1 deletion test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def test_parse_error_incomplete_hash
JSON.parse('{"input":{"firstName":"Bob","lastName":"Mob","email":"[email protected]"}')
end
if RUBY_ENGINE == "ruby"
assert_equal %(unexpected token at '{"input":{"firstName":"Bob","las'), error.message
assert_equal %(expected ',' or '}' after object value, got: ''), error.message
end
end

Expand Down

0 comments on commit ea0db6e

Please sign in to comment.