Skip to content

Commit abe2af4

Browse files
NickNeckjosevalim
authored andcommitted
Fix wildcard edge case (#12255)
1 parent 2a82c35 commit abe2af4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/elixir/lib/path.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ defmodule Path do
603603
:file.read_link_info(file)
604604
end
605605

606+
def read_file_info(file) do
607+
:file.read_file_info(file)
608+
end
609+
606610
def list_dir(dir) do
607611
case :file.list_dir(dir) do
608612
{:ok, files} -> {:ok, for(file <- files, hd(file) != ?., do: file)}

lib/elixir/test/elixir/path_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ defmodule PathTest do
3838
File.rm_rf(Path.join(config.tmp_dir, "wildcard"))
3939
end
4040

41+
@tag :tmp_dir
42+
test "wildcard/2 follows ..", config do
43+
hello = Path.join(config.tmp_dir, "wildcard/hello")
44+
world = Path.join(config.tmp_dir, "wildcard/world")
45+
File.mkdir_p(hello)
46+
File.touch(world)
47+
48+
assert Path.wildcard(Path.join(config.tmp_dir, "wildcard/w*/../h*")) == []
49+
50+
assert Path.wildcard(Path.join(config.tmp_dir, "wildcard/h*/../w*")) ==
51+
[Path.join(config.tmp_dir, "wildcard/hello/../world")]
52+
after
53+
File.rm_rf(Path.join(config.tmp_dir, "wildcard"))
54+
end
55+
4156
test "wildcard/2 raises on null byte" do
4257
assert_raise ArgumentError, ~r/null byte/, fn -> Path.wildcard("foo\0bar") end
4358
end

0 commit comments

Comments
 (0)