Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/wren/src/wren/connector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ def strip_trailing_semicolon(sql: str) -> str:
or ``EXPLAIN SELECT 1;``). Only the *terminating* run of semicolons and
whitespace is removed, so semicolons inside string literals
(``SELECT 'a;b'``) are preserved.

Non-string values are coerced with ``str(...)`` so accidental ``None``/
numeric SQL arguments degrade instead of raising ``TypeError`` inside
the regex. Empty input becomes ``""``.
"""
if sql is None:
return ""
if not isinstance(sql, str):
sql = str(sql)
return _TRAILING_SEMICOLONS_RE.sub("", sql)


Expand Down
14 changes: 14 additions & 0 deletions core/wren/tests/unit/test_strip_trailing_semicolon_coerce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from wren.connector.base import strip_trailing_semicolon


def test_strips_string():
assert strip_trailing_semicolon("SELECT 1;") == "SELECT 1"
assert strip_trailing_semicolon("SELECT 1 ; \n") == "SELECT 1"


def test_none_becomes_empty():
assert strip_trailing_semicolon(None) == ""


def test_non_string_coerced():
assert strip_trailing_semicolon(42) == "42"
Loading