@@ -105,8 +105,34 @@ defmodule Code.Identifier do
105
105
106
106
defp escape_char ( 0 ) , do: [ ?\\ , ?0 ]
107
107
108
- @ escaped_bom :binary . bin_to_list ( "\\ uFEFF" )
109
- defp escape_char ( 65279 ) , do: @ escaped_bom
108
+ defp escape_char ( char )
109
+ # Some characters that are confusing (zero-width / alternative spaces) are displayed
110
+ # using their unicode representation:
111
+ # https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Special-purpose_characters
112
+
113
+ # BOM
114
+ when char == 0xFEFF
115
+ # Mathematical invisibles
116
+ when char in 0x2061 .. 0x2064
117
+ # Bidirectional neutral
118
+ when char in [ 0x061C , 0x200E , 0x200F ]
119
+ # Bidirectional general (source of vulnerabilities)
120
+ when char in 0x202A .. 0x202E
121
+ when char in 0x2066 .. 0x2069
122
+ # Interlinear annotations
123
+ when char in 0xFFF9 .. 0xFFFC
124
+ # Zero-width joiners and non-joiners
125
+ when char in [ 0x200C , 0x200D , 0x034F ]
126
+ # Non-break space / zero-width space
127
+ when char in [ 0x00A0 , 0x200B , 0x2060 ]
128
+ # Line/paragraph separators
129
+ when char in [ 0x2028 , 0x2029 ]
130
+ # Spaces
131
+ when char in 0x2000 .. 0x200A
132
+ when char == 0x205F do
133
+ << a :: 4 , b :: 4 , c :: 4 , d :: 4 >> = << char :: 16 >>
134
+ [ ?\\ , ?u , to_hex ( a ) , to_hex ( b ) , to_hex ( c ) , to_hex ( d ) ]
135
+ end
110
136
111
137
defp escape_char ( char )
112
138
when char in 0x20 .. 0x7E
0 commit comments