1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Improve reporting for syntax errors in multi-line JSON data.

Point to the specific line where the error was detected; the
previous code tended to include several preceding lines as well.
Avoid re-scanning the entire input to recompute which line that
was.  Simplify the logic a bit.  Add test cases.

Simon Riggs and Hamid Akhtar, reviewed by Daniel Gustafsson and myself

Discussion: https://postgr.es/m/CANbhV-EPBnXm3MF_TTWBwwqgn1a1Ghmep9VHfqmNBQ8BT0f+_g@mail.gmail.com
This commit is contained in:
Tom Lane
2021-03-01 16:44:17 -05:00
parent bd69ddfcdb
commit ffd3944ab9
7 changed files with 113 additions and 22 deletions

View File

@ -535,10 +535,12 @@ json_lex(JsonLexContext *lex)
while (len < lex->input_length &&
(*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))
{
if (*s == '\n')
if (*s++ == '\n')
{
++lex->line_number;
++s;
++len;
lex->line_start = s;
}
len++;
}
lex->token_start = s;