More rigorous regexp escaping
This commit is contained in:
parent
ef0f9b986e
commit
c4608279af
@ -149,20 +149,16 @@ private
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def inreplace(path, before, after)
|
||||
before=before.to_s
|
||||
after=after.to_s
|
||||
before=before.to_s.gsub('"', '\"').gsub('/', '\/')
|
||||
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
|
||||
#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
|
||||
`perl -pi -e "s|#{before}|#{after}|g" "#{path}"`
|
||||
#TODO use ed -- less to escape
|
||||
`perl -pi -e "s/#{before}/#{after}/g" "#{path}"`
|
||||
end
|
||||
|
||||
def system cmd
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user