Catch IndentationError in isidentifier()

Fixes:

    >>> from hy._compat import isidentifier
    >>> isidentifier(u"  0\n 0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "hy/_compat.py", line 47, in isidentifier
        tokens = list(T.generate_tokens(StringIO(x).readline))
      File "/usr/lib/python2.7/tokenize.py", line 374, in generate_tokens
        ("<tokenize>", lnum, pos, line))
      File "<tokenize>", line 2
        0
        ^
    IndentationError: unindent does not match any outer indentation level
This commit is contained in:
Jakub Wilk 2018-11-07 20:15:43 +01:00 committed by Kodi Arfer
parent c5abc85a2d
commit 28504ba85d
3 changed files with 6 additions and 1 deletions

View File

@ -30,6 +30,7 @@ Bug Fixes
objects.
* Fixed errors from `from __future__ import ...` statements and missing Hy
module docstrings caused by automatic importing of Hy builtins.
* Fixed crash in `mangle` for some pathological inputs
0.15.0
==============================

View File

@ -45,7 +45,7 @@ def isidentifier(x):
from io import StringIO
try:
tokens = list(T.generate_tokens(StringIO(x).readline))
except T.TokenError:
except (T.TokenError, IndentationError):
return False
return len(tokens) == 2 and tokens[0][0] == T.NAME

View File

@ -157,3 +157,7 @@
["⚘-⚘" "hyx_XflowerX_XflowerX"]]]
(assert (= (mangle a) b))
(assert (= (unmangle b) a))))
(defn test-mangle-bad-indent []
; Shouldn't crash with IndentationError
(mangle " 0\n 0"))