Skip to content

Commit 53f1132

Browse files
committed
Prevent infinite loop on file collision when stdin closed
1 parent 4b95e2e commit 53f1132

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/thor/shell/basic.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ def file_collision(destination)
252252
)
253253

254254
case answer
255+
when nil
256+
say ""
257+
return true
255258
when is?(:yes), is?(:force), ""
256259
return true
257260
when is?(:no), is?(:skip)

spec/shell/basic_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ def #456 Lanç...
310310
shell.file_collision("foo")
311311
end
312312

313+
it "outputs a new line and returns true if stdin is closed" do
314+
expect($stdout).to receive(:print).with("\n")
315+
expect(Thor::LineEditor).to receive(:readline).and_return(nil)
316+
expect(shell.file_collision("foo")).to be true
317+
end
318+
313319
it "returns true if the user chooses default option" do
314320
expect(Thor::LineEditor).to receive(:readline).and_return("")
315321
expect(shell.file_collision("foo")).to be true

0 commit comments

Comments
 (0)