File tree Expand file tree Collapse file tree 3 files changed +35
-5
lines changed Expand file tree Collapse file tree 3 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ instead
38
38
- Fix memory corruption in ` unicode:characters_to_binary `
39
39
- Fix handling of large literal indexes
40
40
- ` unicode:characters_to_list ` : fixed bogus out_of_memory error on some platforms such as ESP32
41
+ - Fix crash in Elixir library when doing ` inspect(:atom) `
41
42
42
43
## [ 0.6.4] - 2024-08-18
43
44
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ defmodule Kernel do
42
42
def inspect ( term , opts \\ [ ] ) when is_list ( opts ) do
43
43
case term do
44
44
t when is_atom ( t ) ->
45
- [ ?: , atom_to_string ( t ) ]
45
+ atom_to_string ( t , ":" )
46
46
47
47
t when is_integer ( t ) ->
48
48
:erlang . integer_to_binary ( t )
@@ -118,10 +118,26 @@ defmodule Kernel do
118
118
)
119
119
end
120
120
121
- defp atom_to_string ( atom ) do
122
- # TODO: use unicode rather than plain latin1
123
- # handle spaces and special characters
124
- :erlang . atom_to_binary ( atom , :latin1 )
121
+ defp atom_to_string ( atom , prefix \\ "" ) do
122
+ case atom do
123
+ true ->
124
+ "true"
125
+
126
+ false ->
127
+ "false"
128
+
129
+ nil ->
130
+ "nil"
131
+
132
+ any_atom ->
133
+ case :erlang . atom_to_binary ( any_atom ) do
134
+ << "Elixir." , displayable :: binary >> ->
135
+ displayable
136
+
137
+ other ->
138
+ << prefix :: binary , other :: binary >>
139
+ end
140
+ end
125
141
end
126
142
127
143
@ doc """
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ defmodule Tests do
26
26
:ok = test_enum ( )
27
27
:ok = test_exception ( )
28
28
:ok = test_chars_protocol ( )
29
+ :ok = test_inspect ( )
29
30
:ok = IO . puts ( "Finished Elixir tests" )
30
31
end
31
32
@@ -234,6 +235,18 @@ defmodule Tests do
234
235
:ok
235
236
end
236
237
238
+ def test_inspect ( ) do
239
+ "true" = inspect ( true )
240
+ "false" = inspect ( false )
241
+ "nil" = inspect ( nil )
242
+
243
+ ":test" = inspect ( :test )
244
+ ":アトム" = inspect ( :アトム )
245
+ "Test" = inspect ( Test )
246
+
247
+ :ok
248
+ end
249
+
237
250
defp fact ( n ) when n < 0 , do: :test
238
251
defp fact ( 0 ) , do: 1
239
252
defp fact ( n ) , do: fact ( n - 1 ) * n
You can’t perform that action at this time.
0 commit comments