Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e75feb2

Browse files
committed
Fix off by one error in JSON extract path code.
Bug report by David Wheeler, diagnosis assistance from Tom Lane.
1 parent 48a2cd3 commit e75feb2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,13 @@ get_array_start(void *state)
682682
ereport(ERROR,
683683
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
684684
errmsg("cannot extract field from a non-object")));
685-
/* initialize array count for this nesting level */
685+
/*
686+
* initialize array count for this nesting level
687+
* Note: the lex_level seen by array_start is one less than that seen by
688+
* the elements of the array.
689+
*/
686690
if (_state->search_type == JSON_SEARCH_PATH &&
687-
lex_level <= _state->npath)
691+
lex_level < _state->npath)
688692
_state->array_level_index[lex_level] = -1;
689693
}
690694

0 commit comments

Comments
 (0)