diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-19 07:50:50 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-19 07:52:46 -0700 |
| commit | b3700f44ff6945d1ace9d5d809dd272c9acd268e (patch) | |
| tree | c4b67697f8158006eaa2ad26fadbcb06817a4c7f | |
| parent | 24f0d3d650d4a83214c4a9539aa04cf4f3045f06 (diff) | |
| download | sqlparse-b3700f44ff6945d1ace9d5d809dd272c9acd268e.tar.gz | |
Previous fix for period failed when another token (non-groupable) followed.
| -rw-r--r-- | sqlparse/engine/grouping.py | 11 | ||||
| -rw-r--r-- | tests/test_grouping.py | 9 |
2 files changed, 17 insertions, 3 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 62357d3..42305c3 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -97,12 +97,17 @@ def group_period(tlist): return imt(token, i=sqlcls, t=ttypes) def valid_next(token): + # issue261, allow invalid next token + return True + + def post(tlist, pidx, tidx, nidx): + # next_ validation is being performed here. issue261 sqlcls = sql.SquareBrackets, sql.Function ttypes = T.Name, T.String.Symbol, T.Wildcard - return token is None or imt(token, i=sqlcls, t=ttypes) + next_ = tlist[nidx] if nidx is not None else None + valid_next = imt(next_, i=sqlcls, t=ttypes) - def post(tlist, pidx, tidx, nidx): - return (pidx, nidx) if nidx is not None else (pidx, tidx) + return (pidx, nidx) if valid_next else (pidx, tidx) _group(tlist, sql.Identifier, match, valid_prev, valid_next, post) diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 107900b..bf6bfeb 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -93,6 +93,15 @@ class TestGrouping(TestCaseBase): self.assertEqual(p.tokens[0].get_real_name(), None) self.assertEqual(p.tokens[0].get_parent_name(), 'a') + def test_identifier_invalid_in_middle(self): + # issue261 + s = 'SELECT foo. FROM foo' + p = sqlparse.parse(s)[0] + assert isinstance(p[2], sql.Identifier) + assert p[2][1].ttype == T.Punctuation + assert p[3].ttype == T.Whitespace + assert str(p[2]) == 'foo.' + def test_identifier_as_invalid(self): # issue8 p = sqlparse.parse('foo as select *')[0] self.assert_(len(p.tokens), 5) |
