Skip to content

Commit

Permalink
using escapes for quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ea-rus committed Jan 12, 2024
1 parent 6f8d1b0 commit 60cc813
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mindsdb_sql/parser/dialects/mindsdb/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ def FLOAT(self, t):
def INTEGER(self, t):
return t

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

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

@_(r'\n+')
Expand Down
26 changes: 26 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 @@ -32,3 +32,29 @@ def test_not_equal(self):
assert str(ast).lower() == str(expected_ast).lower()
assert ast.to_tree() == expected_ast.to_tree()

def test_escaping(self):
expected_ast = Select(
targets=[Constant(value="a ' \" b")]
)

sql = """
select 'a \\' \\" b'
"""

ast = parse_sql(sql)

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

# in double quotes
sql = """
select "a \\' \\" b"
"""

ast = parse_sql(sql)

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



0 comments on commit 60cc813

Please sign in to comment.