Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."

After parsing a parenthesized subexpression, we must pop all pending
ANDs and NOTs off the stack, just like the case for a simple operand.
Per bug #5793.

Also fix clones of this routine in contrib/intarray and contrib/ltree,
where input of types query_int and ltxtquery had the same problem.

Back-patch to all supported versions.
pull/1/head
Tom Lane 15 years ago
parent dcb09b595f
commit abc1026269
  1. 4
      contrib/intarray/_int_bool.c
  2. 4
      contrib/ltree/ltxtquery_io.c
  3. 4
      src/backend/utils/adt/tsquery.c

@ -196,8 +196,8 @@ makepol(WORKSTATE *state)
case OPEN:
if (makepol(state) == ERR)
return ERR;
if (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
{
lenstack--;
pushquery(state, OPR, stack[lenstack]);

@ -241,8 +241,8 @@ makepol(QPRS_STATE *state)
case OPEN:
if (makepol(state) == ERR)
return ERR;
if (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
{
lenstack--;
pushquery(state, OPR, stack[lenstack], 0, 0, 0);

@ -371,8 +371,8 @@ makepol(TSQueryParserState state,
case PT_OPEN:
makepol(state, pushval, opaque);
if (lenstack && (opstack[lenstack - 1] == OP_AND ||
opstack[lenstack - 1] == OP_NOT))
while (lenstack && (opstack[lenstack - 1] == OP_AND ||
opstack[lenstack - 1] == OP_NOT))
{
lenstack--;
pushOperator(state, opstack[lenstack]);

Loading…
Cancel
Save