Skip to content

Commit

Permalink
fix quote is escaped by quote
Browse files Browse the repository at this point in the history
'women''s soccer'
  • Loading branch information
ea-rus committed Sep 19, 2024
1 parent 4c63835 commit 21237be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mindsdb_sql/parser/dialects/mindsdb/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def FLOAT(self, t):
def INTEGER(self, t):
return t

@_(r"'(?:\\.|[^'])*'")
@_(r"'(?:\\.|[^'])*(?:''(?:\\.|[^'])*)*'")
def QUOTE_STRING(self, t):
t.value = t.value.replace('\\"', '"').replace("\\'", "'")
t.value = t.value.replace('\\"', '"').replace("\\'", "'").replace("''", "'")
return t

@_(r'"(?:\\.|[^"])*"')
Expand Down
11 changes: 11 additions & 0 deletions tests/test_parser/test_base_sql/test_base_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,16 @@ def test_escaping(self):
assert str(ast).lower() == str(expected_ast).lower()
assert ast.to_tree() == expected_ast.to_tree()

def test_quotes_escaping(self):
sql = "select 'women''s soccer'"

expected_ast = Select(
targets=[
Constant(value="women's soccer")
]
)
ast = parse_sql(sql)

assert str(ast).lower() == str(expected_ast).lower()
assert ast.to_tree() == expected_ast.to_tree()

0 comments on commit 21237be

Please sign in to comment.