Skip to content

Commit

Permalink
Allow escaping single quotes in single-quoted literal with '' (#3682)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdebelak committed Jul 27, 2022
1 parent 5249e3f commit 7cd64c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sqlfluff/dialects/dialect_ansi.py
Expand Up @@ -85,7 +85,7 @@
WhitespaceSegment,
),
),
RegexLexer("single_quote", r"'([^'\\]|\\.)*'", CodeSegment),
RegexLexer("single_quote", r"'([^'\\]|\\.|'')*'", CodeSegment),
RegexLexer("double_quote", r'"([^"\\]|\\.)*"', CodeSegment),
RegexLexer("back_quote", r"`[^`]*`", CodeSegment),
# See https://www.geeksforgeeks.org/postgresql-dollar-quoted-string-constants/
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/dialects/ansi/escaped_quotes.sql
@@ -1 +1,3 @@
select case when "Spec\"s 23" like 'Spec\'s%' then 'boop' end as field
select case when "Spec\"s 23" like 'Spec\'s%' then 'boop' end as field;
select 'This shouldn''t fail' as success;
15 changes: 13 additions & 2 deletions test/fixtures/dialects/ansi/escaped_quotes.yml
Expand Up @@ -3,9 +3,9 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: d7e3b651df33f7ec8605e1ee45a739bf7d31f858570ccd2190e86b550168ee38
_hash: 0bf4be7b356668afd6b9b4091cc17316ccc1fcdf2757cbad937427c3a77989c6
file:
statement:
- statement:
select_statement:
select_clause:
keyword: select
Expand All @@ -27,3 +27,14 @@ file:
alias_expression:
keyword: as
identifier: field
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: select
select_clause_element:
literal: "'This shouldn''t fail'"
alias_expression:
keyword: as
identifier: success
- statement_terminator: ;

0 comments on commit 7cd64c7

Please sign in to comment.