Merge pull request #1710 from Kodiologist/low-mangling
Fix mangling of characters below 0xFF
This commit is contained in:
commit
c4f73f061f
1
NEWS.rst
1
NEWS.rst
@ -34,6 +34,7 @@ Bug Fixes
|
||||
* 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
|
||||
* Fixed incorrect mangling of some characters at low code points
|
||||
|
||||
0.15.0
|
||||
==============================
|
||||
|
@ -61,7 +61,10 @@ def mangle(s):
|
||||
according to Hy's mangling rules."""
|
||||
def unicode_char_to_hex(uchr):
|
||||
# Covert a unicode char to hex string, without prefix
|
||||
return uchr.encode('unicode-escape').decode('utf-8').lstrip('\\U').lstrip('\\u').lstrip('0')
|
||||
if len(uchr) == 1 and ord(uchr) < 128:
|
||||
return format(ord(uchr), 'x')
|
||||
return (uchr.encode('unicode-escape').decode('utf-8')
|
||||
.lstrip('\\U').lstrip('\\u').lstrip('\\x').lstrip('0'))
|
||||
|
||||
assert s
|
||||
|
||||
|
@ -158,6 +158,27 @@
|
||||
(assert (= (mangle a) b))
|
||||
(assert (= (unmangle b) a))))
|
||||
|
||||
|
||||
(defn test-nongraphic []
|
||||
; https://github.com/hylang/hy/issues/1694
|
||||
|
||||
(assert (= (mangle " ") "hyx_XspaceX"))
|
||||
(assert (= (mangle "\a") "hyx_XU7X"))
|
||||
(assert (= (mangle "\t") "hyx_XU9X"))
|
||||
(assert (= (mangle "\n") "hyx_XUaX"))
|
||||
(assert (= (mangle "\r") "hyx_XUdX"))
|
||||
(assert (= (mangle "\r") "hyx_XUdX"))
|
||||
|
||||
(setv c (try unichr (except [NameError] chr)))
|
||||
(assert (= (mangle (c 127)) "hyx_XU7fX"))
|
||||
(assert (= (mangle (c 128)) "hyx_XU80X"))
|
||||
(assert (= (mangle (c 0xa0)) "hyx_XnoHbreak_spaceX"))
|
||||
(assert (= (mangle (c 0x378)) "hyx_XU378X"))
|
||||
(assert (= (mangle (c 0x200a) "hyx_Xhair_spaceX")))
|
||||
(assert (= (mangle (c 0x2065)) "hyx_XU2065X"))
|
||||
(assert (= (mangle (c 0x1000c)) "hyx_XU1000cX")))
|
||||
|
||||
|
||||
(defn test-mangle-bad-indent []
|
||||
; Shouldn't crash with IndentationError
|
||||
(mangle " 0\n 0"))
|
||||
|
Loading…
Reference in New Issue
Block a user