Skip to content

Commit 6bfcf2f

Browse files
author
José Valim
committed
\d is a printable character
1 parent 45bd250 commit 6bfcf2f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/elixir/lib/inspect.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ end
142142
defimpl Inspect, for: BitString do
143143
def inspect(thing, %Inspect.Opts{binaries: bins} = opts) when is_binary(thing) do
144144
if bins == :as_strings or (bins == :infer and String.printable?(thing)) do
145-
<< ?", escape(thing, ?") :: binary, ?" >>
145+
<<?", escape(thing, ?") :: binary, ?">>
146146
else
147147
inspect_bitstring(thing, opts)
148148
end

lib/elixir/lib/string.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ defmodule String do
143143
def printable?(<<?\b, t :: binary>>), do: printable?(t)
144144
def printable?(<<?\f, t :: binary>>), do: printable?(t)
145145
def printable?(<<?\e, t :: binary>>), do: printable?(t)
146+
def printable?(<<?\d, t :: binary>>), do: printable?(t)
146147
def printable?(<<?\a, t :: binary>>), do: printable?(t)
147148

148149
def printable?(<<>>), do: true

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ defmodule Inspect.BitStringTest do
8686
assert inspect(" ゆんゆん") == "\" ゆんゆん\""
8787
end
8888

89+
test :all_escapes do
90+
assert inspect("\a\b\d\e\f\n\r\s\t\v") ==
91+
"\"\\a\\b\\d\\e\\f\\n\\r \\t\\v\""
92+
end
93+
8994
test :opt_infer do
9095
assert inspect(<<"eric", 193, "mj">>, binaries: :infer) == ~s(<<101, 114, 105, 99, 193, 109, 106>>)
9196
assert inspect(<<"eric">>, binaries: :infer) == ~s("eric")

0 commit comments

Comments
 (0)