Skip to content

Commit

Permalink
Recognize escaped backslashes within strings
Browse files Browse the repository at this point in the history
Previously if a single quoted string ended with an escaped backslash,
parsing would not consider the string to be terminated.
  • Loading branch information
casey committed Feb 26, 2015
1 parent 77e0789 commit e75e358
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions sqlparse/lexer.py
Expand Up @@ -191,8 +191,7 @@ class Lexer(object):
(r'[-]?[0-9]*(\.[0-9]+)?[eE][-]?[0-9]+', tokens.Number.Float),
(r'[-]?[0-9]*\.[0-9]+', tokens.Number.Float),
(r'[-]?[0-9]+', tokens.Number.Integer),
# TODO: Backslash escapes?
(r"'(''|\\'|[^'])*'", tokens.String.Single),
(r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single),
# not a real string literal in ANSI SQL:
(r'(""|".*?[^\\]")', tokens.String.Symbol),
(r'(?<=[\w\]])(\[[^\]]*?\])', tokens.Punctuation.ArrayIndex),
Expand Down
4 changes: 4 additions & 0 deletions tests/test_split.py
Expand Up @@ -22,6 +22,10 @@ def test_split_semicolon(self):
self.ndiffAssertEqual(unicode(stmts[0]), self._sql1)
self.ndiffAssertEqual(unicode(stmts[1]), sql2)

def test_split_backslash(self):
stmts = sqlparse.parse(r"select '\\'; select '\''; select '\\\'';")
self.assertEqual(len(stmts), 3)

def test_create_function(self):
sql = load_file('function.sql')
stmts = sqlparse.parse(sql)
Expand Down

0 comments on commit e75e358

Please sign in to comment.