diff --git a/NEWS.rst b/NEWS.rst index bb101a2..44ab3cb 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -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 ============================== diff --git a/hy/_compat.py b/hy/_compat.py index 4416ea5..379ce43 100644 --- a/hy/_compat.py +++ b/hy/_compat.py @@ -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 diff --git a/tests/native_tests/mangling.hy b/tests/native_tests/mangling.hy index e009ab6..bfb4d0a 100644 --- a/tests/native_tests/mangling.hy +++ b/tests/native_tests/mangling.hy @@ -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"))