From e289164adc985e364f4c3fcb198534321e4aa481 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 23 Oct 2009 19:01:05 +0100 Subject: [PATCH] Implement inreplace natively in Ruby I found yet another instance where the escaping wasn't perfect, so got fed up and just did it in Ruby. I hope this works for all existing usage. It should. The bonus here is that you can use RegExps now. --- Library/Homebrew/utils.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index e9a480ed2b..3981199458 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -149,13 +149,8 @@ end # replaces before with after for the file path def inreplace path, before, after - before=Regexp.escape before.to_s - before.gsub! "/", "\\/" # I guess not escaped as delimiter varies - after=after.to_s - after.gsub! "\\", "\\\\" - after.gsub! "/", "\\/" - after.gsub! "$", "\\$" - - # FIXME use proper Ruby for teh exceptions! - safe_system "/usr/bin/perl", "-pi", "-e", "s/#{before}/#{after}/g", path + f = File.open(path, 'r') + o = f.read.gsub(before, after) + f.reopen(path, 'w').write(o) + f.close end