Skip to content

Commit 54597f2

Browse files
committed
A few more SQLite string fixes, refs #2783
1 parent bf3e277 commit 54597f2

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

datasette/utils/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,11 @@ class StartupError(Exception):
12941294
_comments_and_strings_re = re.compile(
12951295
r"""
12961296
--[^\n]* # single line comment
1297-
| /\*.*?\*/ # multi line comment
1297+
| /\*.*?(?:\*/|\Z) # multi line comment, possibly to end-of-input
12981298
| '(?:''|[^'])*' # single quoted string ('' escapes a quote)
12991299
| "(?:""|[^"])*" # double quoted identifier ("" escapes a quote)
1300+
| \[(?:[^\]])*\] # square-bracket quoted identifier
1301+
| `(?:``|[^`])*` # backtick quoted identifier
13001302
""",
13011303
re.DOTALL | re.VERBOSE,
13021304
)

tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,11 @@ def test_parse_metadata(content, expected):
764764
# Parameters that live inside a comment should be ignored
765765
("select :x -- and :ignored", ["x"]),
766766
("select :x /* and :ignored */ from t", ["x"]),
767+
("select :x /* and :ignored", ["x"]),
768+
# Parameters inside quoted identifiers should be ignored
769+
("select [a:b] from t where id = :id", ["id"]),
770+
("select `a:b` from t where id = :id", ["id"]),
771+
("select `a``:b` from t where id = :id", ["id"]),
767772
# Parameters inside a string literal should be ignored
768773
("select ':ignored' || :real", ["real"]),
769774
),

0 commit comments

Comments
 (0)