Skip to content

Commit

Permalink
cql3: grammar: reject intValue with no contents
Browse files Browse the repository at this point in the history
The grammar mistakenly allows nothing to be parsed as an
intValue (itself accepted in LIMIT and similar clauses).

Easily fixed by removing the empty alternative. A unit test is
added.

Fixes #14705.

Closes #14707
  • Loading branch information
avikivity authored and nyh committed Jul 20, 2023
1 parent 98609e2 commit e00811c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cql3/Cql.g
Expand Up @@ -1622,8 +1622,7 @@ marker returns [uexpression value]
;
intValue returns [uexpression value]
:
| t=INTEGER { $value = untyped_constant{untyped_constant::integer, $t.text}; }
: t=INTEGER { $value = untyped_constant{untyped_constant::integer, $t.text}; }
| e=marker { $value = std::move(e); }
;
Expand Down
24 changes: 24 additions & 0 deletions test/cql-pytest/test_bad_grammar.py
@@ -0,0 +1,24 @@
# Copyright 2023-present ScyllaDB
#
# SPDX-License-Identifier: AGPL-3.0-or-later

# A collection of tests for grammar that should be rejected, but wasn't at
# some point in the past.

import pytest
from util import new_test_table
from cassandra.protocol import InvalidRequest, SyntaxException


# table1 is just there so we can execute bad queries against it.
@pytest.fixture(scope="module")
def table1(cql, test_keyspace):
with new_test_table(cql, test_keyspace, "p int, c int, v int, PRIMARY KEY (p, c)") as table:
yield table

# LIMIT should be followed by an expression (#14705)
def test_limit_empty(cql, table1):
with pytest.raises(SyntaxException):
cql.execute(f'SELECT * FROM {table1} LIMIT')
with pytest.raises(SyntaxException):
cql.execute(f'SELECT * FROM {table1} PER PARTITION LIMIT')

0 comments on commit e00811c

Please sign in to comment.