Skip to content

Commit c4afded

Browse files
committed
fix: pair backslash escapes outside quoted header values
1 parent 095f540 commit c4afded

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/sqlbuild/compiler/discovery/constants.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
SQL_HOOK_IDENTITY_FIELDS: tuple[str, ...] = ("statement", "name", "definition_sql", "kwargs")
7171

7272
STATEMENT_HEADER_BODY_PATTERN: str = (
73-
r"(?P<header>(?>[^\"')]++"
73+
r"(?P<header>(?>(?:[^\"')\\]|\\.)++"
7474
r"|\"(?:[^\"\\]|\\.)*+\""
7575
r"|'(?:[^'\\]|\\.)*+'"
7676
r"|[\"'](?:[^\\)]|\\.)*+"

‎tests/unit/src/sqlbuild/compiler/discovery/_helpers/test_sql_models.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ def test_given_sql_model_header_variants_when_parsing_then_it_returns_expected_h
621621
@pytest.mark.parametrize(
622622
"test_case",
623623
[
624+
ParseModelSqlErrorTestCase(
625+
description="reports an unterminated string with escaped quotes before parentheses",
626+
contents='MODEL (description "' + '\\")' * 20000 + "); SELECT 1",
627+
expected_error_fragment="unterminated double-quoted string",
628+
),
624629
ParseModelSqlErrorTestCase(
625630
description="reports an unterminated string with many escaped quotes",
626631
contents='MODEL (description "' + '\\"' * 20000 + "); SELECT 1",

0 commit comments

Comments
 (0)