Skip to content

Commit 0270144

Browse files
committed
fix: validate SELECT columns as bare identifiers and reject expressions
Non-aggregate SELECT items must be bare column names or *. Rejects arithmetic (age + 1), aggregate wrappers (COUNT(*) + 1), and FILTER clauses at parse time with clear error messages.
1 parent 4edfb43 commit 0270144

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/excel_dbapi/parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ def _parse_columns(columns_token: str) -> List[Any]:
213213
)
214214
columns.append({"type": "aggregate", "func": func, "arg": arg})
215215
continue
216+
if column != "*" and not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", column):
217+
raise ValueError(
218+
f"Unsupported column expression: {column}. "
219+
"Only bare column names, *, and aggregate functions are supported"
220+
)
216221
columns.append(column)
217222
if not columns:
218223
raise ValueError("Invalid column list")

tests/test_parser.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,21 @@ def test_aggregate_rejects_float_literal():
242242
def test_rejects_window_over():
243243
with pytest.raises(ValueError):
244244
parse_sql("SELECT COUNT(*) OVER () FROM users")
245+
246+
247+
def test_rejects_arithmetic_in_select():
248+
with pytest.raises(ValueError, match="Unsupported column expression"):
249+
parse_sql("SELECT age + 1 FROM users")
250+
251+
252+
def test_rejects_aggregate_arithmetic_in_select():
253+
with pytest.raises(
254+
ValueError,
255+
match="Unsupported column expression|Unsupported aggregate",
256+
):
257+
parse_sql("SELECT COUNT(*) + 1 FROM users")
258+
259+
260+
def test_rejects_aggregate_filter_in_select():
261+
with pytest.raises(ValueError, match="Unsupported"):
262+
parse_sql("SELECT COUNT(*) FILTER (WHERE id > 0) FROM users")

0 commit comments

Comments
 (0)