More rigorous regexp escaping

This commit is contained in:
Max Howell 2009-05-22 14:02:11 +01:00
parent ef0f9b986e
commit c4608279af

View File

@ -149,20 +149,16 @@ private
end end
end end
def inreplace(path, before, after) def inreplace(path, before, after)
before=before.to_s before=before.to_s.gsub('"', '\"').gsub('/', '\/')
after=after.to_s after=after.to_s.gsub('"', '\"').gsub('/', '\/')
before.gsub! '"', '\"'
after.gsub! '"', '\"'
before.gsub! '|', '\|"'
after.gsub! '|', '\|"'
# we're not using Ruby because the perl script is more concise # 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 the above escapes are worse, use a proper ruby script :P
#TODO optimise it by taking before and after as arrays #TODO optimise it by taking before and after as arrays
#Bah, just make the script writers do it themselves with a standard collect block #Bah, just make the script writers do it themselves with a standard collect block
`perl -pi -e "s|#{before}|#{after}|g" "#{path}"` #TODO use ed -- less to escape
`perl -pi -e "s/#{before}/#{after}/g" "#{path}"`
end end
def system cmd def system cmd