diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2013-11-06 11:59:52 +0100 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2013-11-06 11:59:52 +0100 |
commit | 6e476cfded15af3d41bcefadecbae51aa65f82ec (patch) | |
tree | c19d84959252e4f55e5815680193b67189ef0628 | |
parent | 5bc149823c2e271ad3a7cf42dac49985d02a1acc (diff) | |
download | sqlparse-6e476cfded15af3d41bcefadecbae51aa65f82ec.tar.gz |
Fix incorrect parsing of string literals with line breaks (fixes #118).
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | sqlparse/lexer.py | 4 | ||||
-rw-r--r-- | tests/test_parse.py | 6 |
3 files changed, 15 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Development +----------- + +Bug Fixes +* Fix incorrect parsing of string literals containing line breaks (issue118). + + Release 0.1.10 (Nov 02, 2013) ----------------------------- diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index d69c938..0d915ac 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -191,7 +191,7 @@ class Lexer(object): (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'(\[.*[^\]]\])', tokens.Name), @@ -209,7 +209,7 @@ class Lexer(object): (r'/\*', tokens.Comment.Multiline, 'multiline-comments'), (r'\*/', tokens.Comment.Multiline, '#pop'), (r'[^/\*]+', tokens.Comment.Multiline), - (r'[/*]', tokens.Comment.Multiline) + (r'[/*]', tokens.Comment.Multiline), ]} def __init__(self): diff --git a/tests/test_parse.py b/tests/test_parse.py index ea29f88..a6145d8 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -169,3 +169,9 @@ def test_double_quotes_are_identifiers(): p = sqlparse.parse('"foo"')[0].tokens assert len(p) == 1 assert isinstance(p[0], sqlparse.sql.Identifier) + + +def test_single_quotes_with_linebreaks(): # issue118 + p = sqlparse.parse("'f\nf'")[0].tokens + assert len(p) == 1 + assert p[0].ttype is T.String.Single |