Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug when destination path contains regexp characters

  • Loading branch information...
commit 033518c44d58c5e08db4c7fb7fbef85b93485e49 1 parent dfdc2aa
@josevalim josevalim authored
Showing with 10 additions and 5 deletions.
  1. +5 −5 lib/thor/actions.rb
  2. +5 −0 spec/actions_spec.rb
View
10 lib/thor/actions.rb
@@ -114,12 +114,12 @@ def destination_root=(root)
# the script started).
#
def relative_to_original_destination_root(path, remove_dot=true)
- if path =~ /^#{Regexp.escape(@destination_stack[0])}/
- path = path.gsub(@destination_stack[0], '.')
- path = remove_dot ? (path[2..-1] || '') : path
+ path = path.dup
+ if path.gsub!(@destination_stack[0], '.')
+ remove_dot ? (path[2..-1] || '') : path
+ else
+ path
end
-
- path
end
# Holds source paths in instance so they can be manipulated.
View
5 spec/actions_spec.rb
@@ -86,6 +86,11 @@ def file
runner.relative_to_original_destination_root('/test/file').should == "/test/file"
end
+ it "does not fail with files constaining regexp characters" do
+ runner = MyCounter.new([1], {}, { :destination_root => File.join(destination_root, "fo[o-b]ar") })
+ runner.relative_to_original_destination_root("bar").should == "bar"
+ end
+
describe "#source_paths_for_search" do
it "add source_root to source_paths_for_search" do
MyCounter.source_paths_for_search.should include(File.expand_path("fixtures", File.dirname(__FILE__)))
Please sign in to comment.
Something went wrong with that request. Please try again.