Skip to content

Commit e95eea4

Browse files
authored
Fix Macro.underscore for digit preceded by capitals, closes #10713 (#10715)
1 parent 3efecd8 commit e95eea4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/elixir/lib/macro.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,8 @@ defmodule Macro do
16711671
end
16721672

16731673
defp do_underscore(<<h, t, rest::binary>>, _)
1674-
when h >= ?A and h <= ?Z and not (t >= ?A and t <= ?Z) and t != ?. and t != ?_ do
1674+
when h >= ?A and h <= ?Z and not (t >= ?A and t <= ?Z) and not (t >= ?0 and t <= ?9) and
1675+
t != ?. and t != ?_ do
16751676
<<?_, to_lower_char(h), t>> <> do_underscore(rest, t)
16761677
end
16771678

lib/elixir/test/elixir/macro_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,10 @@ defmodule MacroTest do
10071007
assert Macro.underscore("FOO_BAR") == "foo_bar"
10081008
assert Macro.underscore("FoBaZa") == "fo_ba_za"
10091009
assert Macro.underscore("Foo10") == "foo10"
1010+
assert Macro.underscore("FOO10") == "foo10"
10101011
assert Macro.underscore("10Foo") == "10_foo"
10111012
assert Macro.underscore("FooBar10") == "foo_bar10"
1013+
assert Macro.underscore("FooBAR10") == "foo_bar10"
10121014
assert Macro.underscore("Foo10Bar") == "foo10_bar"
10131015
assert Macro.underscore("Foo.Bar") == "foo/bar"
10141016
assert Macro.underscore(Foo.Bar) == "foo/bar"

0 commit comments

Comments
 (0)