summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--sqlparse/lexer.py4
-rw-r--r--tests/regressiontests/issue13.py16
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 9afb5e9..d6e95bd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,8 @@ Bug Fixes
* Stricter detection of identfier aliases (issue8, reported by estama).
* WHERE grouping consumed closing parenthesis (issue9, reported by estama).
* Fixed an issue with trailing whitespaces (reported by Kris).
+ * Better detection of escaped single quotes (issue13, reported by
+ Martin Brochhaus, patch by bluemaro with test case by Dan Carley).
Release 0.1.1 (May 6, 2009)
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index a416c16..b7b16af 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -175,8 +175,8 @@ class Lexer:
(r'[+/@#%^&|`?^-]+', Operator),
(r'[0-9]+', Number.Integer),
# TODO: Backslash escapes?
- (r"'(''|[^'])*'", String.Single),
- (r'"(""|[^"])*"', String.Symbol), # not a real string literal in ANSI SQL
+ (r"(''|'.*?[^\\]')", String.Single),
+ (r'(""|".*?[^\\]")', String.Symbol), # not a real string literal in ANSI SQL
(r'(LEFT |RIGHT )?(INNER |OUTER )?JOIN\b', Keyword),
(r'END( IF| LOOP)?\b', Keyword),
(r'CREATE( OR REPLACE)?\b', Keyword.DDL),
diff --git a/tests/regressiontests/issue13.py b/tests/regressiontests/issue13.py
new file mode 100644
index 0000000..d3940e1
--- /dev/null
+++ b/tests/regressiontests/issue13.py
@@ -0,0 +1,16 @@
+import unittest
+
+import sqlparse
+
+
+TEST_SQL = """select 'one';
+select 'two\\'';
+select 'three';"""
+
+
+class TestIssue13(unittest.TestCase):
+
+ def test_quoted(self):
+ parsed = sqlparse.parse(TEST_SQL)
+ self.assertEqual(len(parsed), 3)
+ self.assertEqual(str(parsed[1]).strip(), "select 'two\\'';")