Merge pull request #1691 from jwilk-forks/isidentifier
Catch IndentationError in isidentifier()
This commit is contained in:
commit
3e0112f362
1
NEWS.rst
1
NEWS.rst
@ -30,6 +30,7 @@ Bug Fixes
|
|||||||
objects.
|
objects.
|
||||||
* Fixed errors from `from __future__ import ...` statements and missing Hy
|
* Fixed errors from `from __future__ import ...` statements and missing Hy
|
||||||
module docstrings caused by automatic importing of Hy builtins.
|
module docstrings caused by automatic importing of Hy builtins.
|
||||||
|
* Fixed crash in `mangle` for some pathological inputs
|
||||||
|
|
||||||
0.15.0
|
0.15.0
|
||||||
==============================
|
==============================
|
||||||
|
@ -45,7 +45,7 @@ def isidentifier(x):
|
|||||||
from io import StringIO
|
from io import StringIO
|
||||||
try:
|
try:
|
||||||
tokens = list(T.generate_tokens(StringIO(x).readline))
|
tokens = list(T.generate_tokens(StringIO(x).readline))
|
||||||
except T.TokenError:
|
except (T.TokenError, IndentationError):
|
||||||
return False
|
return False
|
||||||
return len(tokens) == 2 and tokens[0][0] == T.NAME
|
return len(tokens) == 2 and tokens[0][0] == T.NAME
|
||||||
|
|
||||||
|
@ -157,3 +157,7 @@
|
|||||||
["⚘-⚘" "hyx_XflowerX_XflowerX"]]]
|
["⚘-⚘" "hyx_XflowerX_XflowerX"]]]
|
||||||
(assert (= (mangle a) b))
|
(assert (= (mangle a) b))
|
||||||
(assert (= (unmangle b) a))))
|
(assert (= (unmangle b) a))))
|
||||||
|
|
||||||
|
(defn test-mangle-bad-indent []
|
||||||
|
; Shouldn't crash with IndentationError
|
||||||
|
(mangle " 0\n 0"))
|
||||||
|
Loading…
Reference in New Issue
Block a user