diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-03-01 16:44:17 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-03-01 16:44:17 -0500 |
commit | ffd3944ab9d481906137bc7d20f5325a2bd68acc (patch) | |
tree | 6c9b03abc608dc3ea73d8baf9179e9426016ca5d /src/common/jsonapi.c | |
parent | bd69ddfcdbf650f11af4317f3f6686c012cf66d0 (diff) | |
download | postgresql-ffd3944ab9d481906137bc7d20f5325a2bd68acc.tar.gz postgresql-ffd3944ab9d481906137bc7d20f5325a2bd68acc.zip |
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
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r-- | src/common/jsonapi.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c index 831a44a2da6..1bf38d7b429 100644 --- a/src/common/jsonapi.c +++ b/src/common/jsonapi.c @@ -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; |