Skip to content

Commit 31d7acc

Browse files
committed
Escape the diff tool as well
1 parent 1b95317 commit 31d7acc

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

lib/thor/shell/basic.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,11 @@ def file_collision_help(block_given) #:nodoc:
311311
end
312312

313313
def show_diff(destination, content) #:nodoc:
314-
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
315-
316314
require "tempfile"
317315
Tempfile.open(File.basename(destination), File.dirname(destination), binmode: true) do |temp|
318316
temp.write content
319317
temp.rewind
320-
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
318+
system(*diff_tool, destination, temp.path)
321319
end
322320
end
323321

@@ -382,6 +380,13 @@ def merge_tool #:nodoc:
382380
Shellwords.split(ENV["THOR_MERGE"] || "git difftool --no-index")
383381
end
384382
end
383+
384+
def diff_tool #:nodoc:
385+
@diff_cmd ||= begin
386+
require "shellwords"
387+
Shellwords.split(ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u")
388+
end
389+
end
385390
end
386391
end
387392
end

spec/actions/create_file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def silence!
134134
it "executes the block given to show file content" do
135135
create_file("doc/config.rb")
136136
expect(Thor::LineEditor).to receive(:readline).and_return("d", "n")
137-
expect(@base.shell).to receive(:system).with(/diff -u/)
137+
expect(@base.shell).to receive(:system).with("diff", "-u", /doc\/config\.rb/, /doc\/config\.rb/)
138138
invoke!
139139
end
140140

spec/actions/file_manipulation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def file
9494
File.write(destination, "blabla")
9595

9696
expect(Thor::LineEditor).to receive(:readline).and_return("d", "y")
97-
expect(runner.shell).to receive(:system).with(/diff -u/)
97+
expect(runner.shell).to receive(:system).with("diff", "-u", /encoding_with_utf8.thor/, /encoding_with_utf8.thor/)
9898
action :copy_file, "encoding_with_utf8.thor"
9999

100100
exists_and_identical?("encoding_with_utf8.thor", "encoding_with_utf8.thor")

spec/shell/basic_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def #456 Lanç...
546546
it "invokes the diff command" do
547547
expect(Thor::LineEditor).to receive(:readline).and_return("d")
548548
expect(Thor::LineEditor).to receive(:readline).and_return("n")
549-
expect(shell).to receive(:system).with(/diff -u/)
549+
expect(shell).to receive(:system).with("diff", "-u", "foo", /foo/)
550550
capture(:stdout) { shell.file_collision("foo") {} }
551551
end
552552

0 commit comments

Comments
 (0)