summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEksperimental <eksperimental@autistici.org>2021-12-05 09:51:52 +0000
committerGitHub <noreply@github.com>2021-12-05 10:51:52 +0100
commit6f98831d8822b364d4d2184df4130fcaa7b95ff5 (patch)
treec887ce073cc87f79e3789a135ff57175f1ce759f
parent4dd1301d03ce5e840c73220e9d0940f5b78f5d92 (diff)
downloadelixir-6f98831d8822b364d4d2184df4130fcaa7b95ff5.tar.gz
Fix spec for Code.Identifier.escape/4 (#11445)
Closes #11444
-rw-r--r--lib/elixir/lib/code/identifier.ex5
-rw-r--r--lib/elixir/lib/code/normalizer.ex4
-rw-r--r--lib/ex_unit/lib/ex_unit/diff.ex10
3 files changed, 10 insertions, 9 deletions
diff --git a/lib/elixir/lib/code/identifier.ex b/lib/elixir/lib/code/identifier.ex
index 51f254558..8f60c69cc 100644
--- a/lib/elixir/lib/code/identifier.ex
+++ b/lib/elixir/lib/code/identifier.ex
@@ -214,10 +214,11 @@ defmodule Code.Identifier do
@doc """
Escapes the given identifier.
"""
- @spec escape(binary(), char(), :infinity | non_neg_integer, (char() -> iolist() | false)) ::
+ @spec escape(binary(), char() | nil, :infinity | non_neg_integer, (char() -> iolist() | false)) ::
{escaped :: iolist(), remaining :: binary()}
def escape(binary, char, limit \\ :infinity, fun \\ &escape_map/1)
- when limit == :infinity or (is_integer(limit) and limit >= 0) do
+ when ((char in 0..0x10FFFF or is_nil(char)) and limit == :infinity) or
+ (is_integer(limit) and limit >= 0) do
escape(binary, char, limit, [], fun)
end
diff --git a/lib/elixir/lib/code/normalizer.ex b/lib/elixir/lib/code/normalizer.ex
index c0a92dded..be455f274 100644
--- a/lib/elixir/lib/code/normalizer.ex
+++ b/lib/elixir/lib/code/normalizer.ex
@@ -277,7 +277,7 @@ defmodule Code.Normalizer do
# It's a charlist
list =
if state.escape do
- {string, _} = Code.Identifier.escape(IO.chardata_to_string(list), -1)
+ {string, _} = Code.Identifier.escape(IO.chardata_to_string(list), nil)
IO.iodata_to_binary(string) |> to_charlist()
else
list
@@ -511,7 +511,7 @@ defmodule Code.Normalizer do
end
defp maybe_escape_literal(string, %{escape: true}) when is_binary(string) do
- {string, _} = Code.Identifier.escape(string, -1)
+ {string, _} = Code.Identifier.escape(string, nil)
IO.iodata_to_binary(string)
end
diff --git a/lib/ex_unit/lib/ex_unit/diff.ex b/lib/ex_unit/lib/ex_unit/diff.ex
index 7656cfaf3..290ecaf3c 100644
--- a/lib/ex_unit/lib/ex_unit/diff.ex
+++ b/lib/ex_unit/lib/ex_unit/diff.ex
@@ -671,13 +671,13 @@ defmodule ExUnit.Diff do
{:ok, inspect_left} <- safe_inspect(left),
{:ok, inspect_right} <- safe_inspect(right) do
if inspect_left != inspect_right do
- diff_string(inspect_left, inspect_right, :none, env)
+ diff_string(inspect_left, inspect_right, nil, env)
else
# If they are equivalent, still use their inspected form
case diff_map(kw, right, struct1, struct2, env) do
{%{equivalent?: true}, ctx} ->
- left = block_diff_container([inspect_left], :none)
- right = block_diff_container([inspect_right], :none)
+ left = block_diff_container([inspect_left], nil)
+ right = block_diff_container([inspect_right], nil)
{%__MODULE__{equivalent?: true, left: left, right: right}, ctx}
diff_ctx ->
@@ -853,7 +853,7 @@ defmodule ExUnit.Diff do
end
end
- defp block_diff_container(contents, :none),
+ defp block_diff_container(contents, nil),
do: {:__block__, [], contents}
defp block_diff_container(contents, container),
@@ -880,7 +880,7 @@ defmodule ExUnit.Diff do
# Numbers
defp diff_number(left, right, env) do
- diff_string(inspect(left), inspect(right), :none, env)
+ diff_string(inspect(left), inspect(right), nil, env)
end
# Algebra