Skip to content

Commit 17efb65

Browse files
CvXMaxLap
authored andcommitted
Remove the root path from the absolute path only once
In cases where root path is also a substring of a relative path, it was being erroneously removed twice (or more). e.g. for absolute path /app/config/application.rb when root is /app it would display relative path as config.lication.rb instead of config/application.rb
1 parent c90d0ab commit 17efb65

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/thor/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def destination_root=(root)
114114
#
115115
def relative_to_original_destination_root(path, remove_dot = true)
116116
path = path.dup
117-
if path.gsub!(@destination_stack[0], ".")
117+
if path.sub!(@destination_stack[0], ".")
118118
remove_dot ? (path[2..-1] || "") : path
119119
else
120120
path

spec/actions_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def file
8686
expect(runner.relative_to_original_destination_root("/test/file")).to eq("/test/file")
8787
end
8888

89+
it "removes the root path from the absolute path only once" do
90+
runner.destination_root = "/app"
91+
expect(runner.relative_to_original_destination_root("/app/project/application")).to eq("project/application")
92+
end
93+
8994
it "does not fail with files containing regexp characters" do
9095
runner = MyCounter.new([1], {}, :destination_root => File.join(destination_root, "fo[o-b]ar"))
9196
expect(runner.relative_to_original_destination_root("bar")).to eq("bar")

0 commit comments

Comments
 (0)