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 <[email protected]>
Signed-off-by: Cameron Thomas <[email protected]>
---
Local-branch: feature/master/8272-windows_service_support
 install.rb |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/install.rb b/install.rb
index dcff824..784ec8c 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>', ruby.gsub(%r{/}) { "\\" 
}).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
+      regex_safe_ruby = Regexp.escape(ruby.gsub(%r{/}) { "\\" })
+      regex_safe_cwn = Regexp.escape(cwn.gsub(%r{/}) { "\\" })
 
+      cwv = CMD_WRAPPER.gsub('<ruby>', regex_safe_ruby).gsub('<command>', 
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)
 
-- 
1.7.5.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to