aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2009-07-27 16:18:47 +0100
committerMax Howell2009-07-27 16:20:48 +0100
commitd8a944e83df880c6b217d3589f19a6daa88c5659 (patch)
tree2699b2fe00b5dc905f22e013760f6a8ed98ca5e7 /Library
parent3605b8d2310bb2f519a4793346c7709f4c87d327 (diff)
downloadhomebrew-d8a944e83df880c6b217d3589f19a6daa88c5659.tar.bz2
Fix inreplace when using ' or other RegExp symbols
Evidence that using perl from the cli for in-replace is stupid :P Had to use $'' to allow escaping of ' in bash strings. Wasn't escaping regexp symbols as well, so it was amazing this worked at all!
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/brewkit.rb23
1 files changed, 10 insertions, 13 deletions
diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb
index 2cf483280..94cb8a014 100644
--- a/Library/Homebrew/brewkit.rb
+++ b/Library/Homebrew/brewkit.rb
@@ -36,18 +36,15 @@ unless $root.to_s == '/usr/local'
ENV['LDFLAGS']='-L'+$root+'lib'
end
-
-######################################################################## utils
-
def inreplace(path, before, after)
- before=before.to_s.gsub('"', '\"').gsub('/', '\/')
- after=after.to_s.gsub('"', '\"').gsub('/', '\/')
-
- # we're not using Ruby because the perl script is more concise
- #TODO the above escapes are worse, use a proper ruby script :P
- #TODO optimise it by taking before and after as arrays
- #Bah, just make the script writers do it themselves with a standard collect block
- #TODO use ed -- less to escape
- #TODO the above doesn't escape all regexp symbols!
- `perl -pi -e "s/#{before}/#{after}/g" "#{path}"`
+ before=Regexp.escape before.to_s
+ after=Regexp.escape after.to_s
+ before=before.gsub "/", "\\\/"
+ after=after.gsub "/", "\\\/"
+ before=before.gsub "'", '\''
+ after=after.gsub "'", '\''
+
+ # TODO this sucks
+ # either use 'ed', or allow regexp and use a proper ruby function
+ `perl -pi -e $'s/#{before}/#{after}/g' "#{path}"`
end