mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
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!
This commit is contained in:
parent
7ebe8084ec
commit
822a30e39d
@ -36,18 +36,15 @@ unless $root.to_s == '/usr/local'
|
|||||||
ENV['LDFLAGS']='-L'+$root+'lib'
|
ENV['LDFLAGS']='-L'+$root+'lib'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
######################################################################## utils
|
|
||||||
|
|
||||||
def inreplace(path, before, after)
|
def inreplace(path, before, after)
|
||||||
before=before.to_s.gsub('"', '\"').gsub('/', '\/')
|
before=Regexp.escape before.to_s
|
||||||
after=after.to_s.gsub('"', '\"').gsub('/', '\/')
|
after=Regexp.escape after.to_s
|
||||||
|
before=before.gsub "/", "\\\/"
|
||||||
|
after=after.gsub "/", "\\\/"
|
||||||
|
before=before.gsub "'", '\''
|
||||||
|
after=after.gsub "'", '\''
|
||||||
|
|
||||||
# we're not using Ruby because the perl script is more concise
|
# TODO this sucks
|
||||||
#TODO the above escapes are worse, use a proper ruby script :P
|
# either use 'ed', or allow regexp and use a proper ruby function
|
||||||
#TODO optimise it by taking before and after as arrays
|
`perl -pi -e $'s/#{before}/#{after}/g' "#{path}"`
|
||||||
#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}"`
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user