A few more SQLite string fixes, refs #2783

This commit is contained in:
Simon Willison 2026-07-07 14:26:34 -07:00
commit 54597f22fa
2 changed files with 8 additions and 1 deletions

View file

@ -1294,9 +1294,11 @@ class StartupError(Exception):
_comments_and_strings_re = re.compile(
r"""
--[^\n]* # single line comment
| /\*.*?\*/ # multi line comment
| /\*.*?(?:\*/|\Z) # multi line comment, possibly to end-of-input
| '(?:''|[^'])*' # single quoted string ('' escapes a quote)
| "(?:""|[^"])*" # double quoted identifier ("" escapes a quote)
| \[(?:[^\]])*\] # square-bracket quoted identifier
| `(?:``|[^`])*` # backtick quoted identifier
""",
re.DOTALL | re.VERBOSE,
)

View file

@ -764,6 +764,11 @@ def test_parse_metadata(content, expected):
# Parameters that live inside a comment should be ignored
("select :x -- and :ignored", ["x"]),
("select :x /* and :ignored */ from t", ["x"]),
("select :x /* and :ignored", ["x"]),
# Parameters inside quoted identifiers should be ignored
("select [a:b] from t where id = :id", ["id"]),
("select `a:b` from t where id = :id", ["id"]),
("select `a``:b` from t where id = :id", ["id"]),
# Parameters inside a string literal should be ignored
("select ':ignored' || :real", ["real"]),
),