From b7b5a60f864e411f979c4ad5886da582bb86b547 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Wed, 20 Nov 2019 19:10:15 +0000 Subject: [PATCH] utils/inreplace: do not allow to use empty list of files --- Library/Homebrew/test/inreplace_spec.rb | 6 ++++++ Library/Homebrew/utils/inreplace.rb | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Library/Homebrew/test/inreplace_spec.rb b/Library/Homebrew/test/inreplace_spec.rb index 55edc5437e..7b5901b94a 100644 --- a/Library/Homebrew/test/inreplace_spec.rb +++ b/Library/Homebrew/test/inreplace_spec.rb @@ -228,6 +228,12 @@ describe Utils::Inreplace do after { file.unlink } + it "raises error if there are no files given to replace" do + expect { + described_class.inreplace [], "d", "f" + }.to raise_error(Utils::InreplaceError) + end + it "raises error if there is nothing to replace" do expect { described_class.inreplace file.path, "d", "f" diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 3bce563f7c..59f2552679 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -22,6 +22,8 @@ module Utils def inreplace(paths, before = nil, after = nil, audit_result = true) errors = {} + errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank? + Array(paths).each do |path| s = File.open(path, "rb", &:read).extend(StringInreplaceExtension)