Skip to content

Commit 606a22f

Browse files
author
José Valim
committed
Fix inspect for Regexes with terminator, closes #6255
1 parent a3d6aea commit 606a22f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/elixir/lib/inspect.ex

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,31 +417,28 @@ defimpl Inspect, for: Regex do
417417
defp escape(bin, term),
418418
do: escape(bin, [], term)
419419

420-
defp escape(<<?\\, term>> <> rest, buf, term),
421-
do: escape(rest, [buf | [?\\, term]], term)
422-
423-
defp escape(<<term>> <> rest, buf, term),
420+
defp escape(<<term, rest::binary>>, buf, term),
424421
do: escape(rest, [buf | [?\\, term]], term)
425422

426423
# The list of characters is from 'String.printable?' implementation
427424
# minus characters treated specially by regex: \s, \d, \b, \e
428425

429-
defp escape(<<?\n>> <> rest, buf, term),
426+
defp escape(<<?\n, rest::binary>>, buf, term),
430427
do: escape(rest, [buf | '\\n'], term)
431428

432-
defp escape(<<?\r>> <> rest, buf, term),
429+
defp escape(<<?\r, rest::binary>>, buf, term),
433430
do: escape(rest, [buf | '\\r'], term)
434431

435-
defp escape(<<?\t>> <> rest, buf, term),
432+
defp escape(<<?\t, rest::binary>>, buf, term),
436433
do: escape(rest, [buf | '\\t'], term)
437434

438-
defp escape(<<?\v>> <> rest, buf, term),
435+
defp escape(<<?\v, rest::binary>>, buf, term),
439436
do: escape(rest, [buf | '\\v'], term)
440437

441-
defp escape(<<?\f>> <> rest, buf, term),
438+
defp escape(<<?\f, rest::binary>>, buf, term),
442439
do: escape(rest, [buf | '\\f'], term)
443440

444-
defp escape(<<?\a>> <> rest, buf, term),
441+
defp escape(<<?\a, rest::binary>>, buf, term),
445442
do: escape(rest, [buf | '\\a'], term)
446443

447444
defp escape(<<char::utf8, rest::binary>>, buf, term)

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,9 @@ defmodule Inspect.OthersTest do
560560
"~r/\\a\\x08\\x7F\\x1B\\f\\n\\r \\t\\v\\//"
561561
assert inspect(~r<\a\b\d\e\f\n\r\s\t\v/>) ==
562562
"~r/\\a\\b\\d\\e\\f\\n\\r\\s\\t\\v\\//"
563-
opts = [syntax_colors: [regex: :red]]
564-
assert inspect(~r/hi/, opts) ==
563+
assert inspect(~r" \\/ ") ==
564+
"~r/ \\\\\\/ /"
565+
assert inspect(~r/hi/, syntax_colors: [regex: :red]) ==
565566
"\e[31m~r/hi/\e[0m"
566567
end
567568
end

0 commit comments

Comments
 (0)