diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2016-09-14 14:45:44 +0200 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2016-09-14 14:45:44 +0200 |
commit | 358ad4b9754721f69c6b40333653bd84edb8634f (patch) | |
tree | e60e2f544353dc6037203ea7819fe764d36306e3 | |
parent | 7dd1ff99fe433d763840172eef7c14dc0c282d4f (diff) | |
download | sqlparse-358ad4b9754721f69c6b40333653bd84edb8634f.tar.gz |
Fix parsing of names containing special chars (fixes 291).
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | sqlparse/keywords.py | 4 | ||||
-rw-r--r-- | tests/test_tokenize.py | 14 |
3 files changed, 17 insertions, 2 deletions
@@ -4,6 +4,7 @@ Development Version Bug Fixes * Fix parsing of incomplete AS (issue284, by vmuriart). +* Fix parsing of Oracle names containing dollars (issue291). Internal Changes diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index dee4030..22d872e 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -39,7 +39,7 @@ SQL_REGEX = { (r'\?', tokens.Name.Placeholder), (r'%(\(\w+\))?s', tokens.Name.Placeholder), - (r'[$:?]\w+', tokens.Name.Placeholder), + (r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder), # FIXME(andi): VALUES shouldn't be listed here # see https://github.com/andialbrecht/sqlparse/pull/64 @@ -76,7 +76,7 @@ SQL_REGEX = { (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL), (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), - (r'[_A-Z]\w*', is_keyword), + (r'[_A-Z][_$#\w]*', is_keyword), (r'[;:()\[\],\.]', tokens.Punctuation), (r'[<>=~!]+', tokens.Operator.Comparison), diff --git a/tests/test_tokenize.py b/tests/test_tokenize.py index 93645d8..22cb90f 100644 --- a/tests/test_tokenize.py +++ b/tests/test_tokenize.py @@ -163,3 +163,17 @@ def test_parse_endifloop(s): p = sqlparse.parse(s)[0] assert len(p.tokens) == 1 assert p.tokens[0].ttype is T.Keyword + + +@pytest.mark.parametrize('s', [ + 'foo', + 'Foo', + 'FOO', + 'v$name', # issue291 +]) +def test_parse_identifiers(s): + p = sqlparse.parse(s)[0] + assert len(p.tokens) == 1 + token = p.tokens[0] + assert str(token) == s + assert isinstance(token, sql.Identifier) |