mirror of
https://github.com/simonw/datasette.git
synced 2026-07-09 17:14:35 +02:00
Fix named_parameters when string literals contain comment markers (#2783)
named_parameters stripped SQL comments before string literals in
separate passes. A string literal such as '-- TODO' would be treated
as the start of a line comment, swallowing the rest of the line and
hiding any named parameters that followed it. For example:
select * from t where note = '-- TODO' and id = :id
returned [] instead of ['id'], so the query parameter input form
would be missing the :id field.
Match comments and string literals in a single left-to-right pass so
that whichever construct starts first wins, matching how SQL is
actually tokenized.
Co-authored-by: JSap0914 <JSap0914@users.noreply.github.com>
This commit is contained in:
parent
211e70d4e1
commit
bf3e277c98
2 changed files with 25 additions and 8 deletions
|
|
@ -756,6 +756,16 @@ def test_parse_metadata(content, expected):
|
|||
("select 1 + :one + :two", ["one", "two"]),
|
||||
("select 'bob' || '0:00' || :cat", ["cat"]),
|
||||
("select this is invalid :one, :two, :three", ["one", "two", "three"]),
|
||||
# A string literal containing a comment marker should not hide
|
||||
# parameters that come after it
|
||||
("select * from t where note = '-- TODO' and id = :id", ["id"]),
|
||||
("select '--' || :y", ["y"]),
|
||||
("select * from t where note = '/* x */' and id = :id", ["id"]),
|
||||
# Parameters that live inside a comment should be ignored
|
||||
("select :x -- and :ignored", ["x"]),
|
||||
("select :x /* and :ignored */ from t", ["x"]),
|
||||
# Parameters inside a string literal should be ignored
|
||||
("select ':ignored' || :real", ["real"]),
|
||||
),
|
||||
)
|
||||
@pytest.mark.parametrize("use_async_version", (False, True))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue