Skip to content

Commit e70f2ec

Browse files
committed
Make sure duplicates are remove from PATH.
1 parent 0bb9b49 commit e70f2ec

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Library/Homebrew/PATH.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ def initialize(*paths)
44
end
55

66
def prepend(*paths)
7-
@paths.unshift(*parse(*paths))
7+
@paths = parse(*paths, *@paths)
88
self
99
end
1010

1111
def append(*paths)
12-
@paths.concat(parse(*paths))
12+
@paths = parse(*@paths, *paths)
1313
self
1414
end
1515

Library/Homebrew/test/PATH_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
it "splits an existing PATH" do
1414
expect(described_class.new("/path1:/path2")).to eq(["/path1", "/path2"])
1515
end
16+
17+
it "removes duplicates" do
18+
expect(described_class.new("/path1", "/path1")).to eq("/path1")
19+
end
1620
end
1721

1822
describe "#to_ary" do
@@ -31,12 +35,20 @@
3135
it "prepends a path to a PATH" do
3236
expect(described_class.new("/path1").prepend("/path2").to_str).to eq("/path2:/path1")
3337
end
38+
39+
it "removes duplicates" do
40+
expect(described_class.new("/path1").prepend("/path1").to_str).to eq("/path1")
41+
end
3442
end
3543

3644
describe "#append" do
3745
it "prepends a path to a PATH" do
3846
expect(described_class.new("/path1").append("/path2").to_str).to eq("/path1:/path2")
3947
end
48+
49+
it "removes duplicates" do
50+
expect(described_class.new("/path1").append("/path1").to_str).to eq("/path1")
51+
end
4052
end
4153

4254
describe "#validate" do

0 commit comments

Comments
 (0)