From d9a693dc4431430fcfdc3ae15bee8b4a0985868f Mon Sep 17 00:00:00 2001 From: Cameron Thomas Date: Fri, 22 Jul 2011 14:31:59 -0700 Subject: Regexp escape substituted commands in Windows wrapper script Because Windows file paths can (and do) contain '\', they can end up being interpreted as back-references on the substitution side of gsub. Since this is not at all what is intended, we use Regexp.escape to quote them. Reviewed-by: Jacob Helwig (cherry picked from commit ca2f159caed691936bd9e87b59ccddc764066aa2) --- install.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.rb b/install.rb index dcff82403..784ec8c9b 100755 --- a/install.rb +++ b/install.rb @@ -405,8 +405,10 @@ def install_binfile(from, op_file, target) if not installed_wrapper tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') cwn = File.join(Config::CONFIG['bindir'], op_file) - cwv = CMD_WRAPPER.gsub('', ruby.gsub(%r{/}) { "\\" }).gsub!('', cwn.gsub(%r{/}) { "\\" } ) + regex_safe_ruby = Regexp.escape(ruby.gsub(%r{/}) { "\\" }) + regex_safe_cwn = Regexp.escape(cwn.gsub(%r{/}) { "\\" }) + cwv = CMD_WRAPPER.gsub('', regex_safe_ruby).gsub('', regex_safe_cwn) File.open(tmp_file2, "wb") { |cw| cw.puts cwv } FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) -- cgit