Skip to content

Commit ea0db6e

Browse files
committed
Fix the remaining error message asserting tests
1 parent 0aabbc5 commit ea0db6e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

ext/json/ext/parser/parser.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,15 @@ static VALUE json_parse_any(JSON_ParserState *state)
891891
return PUSH(Qnil);
892892
}
893893

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

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

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

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

928-
raise_parse_error("unexpected character", state->cursor);
928+
raise_parse_error("unexpected token at '%s'", state->cursor);
929929
break;
930930
case '-':
931931
// Note: memcmp with a small power of two compile to an integer comparison
932-
if (state->config->allow_nan && (state->end - state->cursor >= 9) && (memcmp(state->cursor + 1, "Infinity", 8) == 0)) {
933-
state->cursor += 9;
934-
return PUSH(CMinusInfinity);
932+
if ((state->end - state->cursor >= 9) && (memcmp(state->cursor + 1, "Infinity", 8) == 0)) {
933+
if (state->config->allow_nan) {
934+
state->cursor += 9;
935+
return PUSH(CMinusInfinity);
936+
} else {
937+
raise_parse_error("unexpected token at '%s'", state->cursor);
938+
}
935939
}
936940
// Fallthrough
937941
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': {

test/json/json_parser_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def test_parse_error_incomplete_hash
625625
JSON.parse('{"input":{"firstName":"Bob","lastName":"Mob","email":"[email protected]"}')
626626
end
627627
if RUBY_ENGINE == "ruby"
628-
assert_equal %(unexpected token at '{"input":{"firstName":"Bob","las'), error.message
628+
assert_equal %(expected ',' or '}' after object value, got: ''), error.message
629629
end
630630
end
631631

0 commit comments

Comments
 (0)