Merge pull request #381 from phst/end-of-file-error-code
Use a more specific error code for premature end of input
This commit is contained in:
commit
46dff2737d
@ -122,6 +122,10 @@ static void error_set(json_error_t *error, const lex_t *lex,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(code == json_error_invalid_syntax) {
|
||||||
|
/* More specific error code for premature end of file. */
|
||||||
|
code = json_error_premature_end_of_input;
|
||||||
|
}
|
||||||
if(lex->stream.state == STREAM_STATE_ERROR) {
|
if(lex->stream.state == STREAM_STATE_ERROR) {
|
||||||
/* No context for UTF-8 decoding errors */
|
/* No context for UTF-8 decoding errors */
|
||||||
result = msg_text;
|
result = msg_text;
|
||||||
|
@ -221,6 +221,14 @@ static void error_code()
|
|||||||
fail("error.text longer than expected");
|
fail("error.text longer than expected");
|
||||||
if(json_error_code(&error) != json_error_end_of_input_expected)
|
if(json_error_code(&error) != json_error_end_of_input_expected)
|
||||||
fail("json_loads returned incorrect error code");
|
fail("json_loads returned incorrect error code");
|
||||||
|
|
||||||
|
json = json_loads("{\"foo\": ", 0, &error);
|
||||||
|
if(json != NULL)
|
||||||
|
fail("json_loads returned not NULL");
|
||||||
|
if(strlen(error.text) >= JSON_ERROR_TEXT_LENGTH)
|
||||||
|
fail("error.text longer than expected");
|
||||||
|
if(json_error_code(&error) != json_error_premature_end_of_input)
|
||||||
|
fail("json_loads returned incorrect error code");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_tests()
|
static void run_tests()
|
||||||
|
Loading…
Reference in New Issue
Block a user