Please review pull request #100: (#10885) Malformed facter.bat when ruby path contains backreferences opened by (joshcooper)

Description:

Previously, we were substituting occurrences of and
in the Windows batch wrapper scripts with the corresponding
paths. However,the gsub replacement string was not escaped, so if a
path contained something that looked like a backreference,
e.g. C:\ruby\187, the gsub would try to replace the backreference with
the corresponding capture group. Since there aren't any capture
groups, the backreference was stripped from resulting facter.bat,
resulting in an invalid path, C:\ruby87\bin\facter.

This commit eliminates the need for gsub, since paths can contain
other characters that have special meaning in a regexp, e.g. '.'.

It also writes the bat file in 'text' mode so that the resulting file
has '\r\n' line endings.

  • Opened: Wed Nov 16 18:39:22 UTC 2011
  • Based on: puppetlabs:1.6.x (e466ffd2ce6609be6470702e600d026030b52532)
  • Requested merge: joshcooper:ticket/1.6.x/10885-facter-backreferences (bdbb2dad7d875ec20824854a0f41981b7fb3aa73)

Diff follows:

diff --git a/install.rb b/install.rb
index 065ce68..30af4f4 100755
--- a/install.rb
+++ b/install.rb
@@ -418,9 +418,17 @@ 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{/}) { "\\" } )
-
-      File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
+      cwv = <<-EOS
+@echo off
+if "%OS%"=="Windows_NT" goto WinNT
+#{ruby} -x "#{cwn}" %1 %2 %3 %4 %5 %6 %7 %8 %9
+goto done
+:WinNT
+#{ruby} -x "#{cwn}" %*
+goto done
+:done
+EOS
+      File.open(tmp_file2, "w") { |cw| cw.puts cwv }
       FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
 
       File.unlink(tmp_file2)
@@ -431,17 +439,6 @@ def install_binfile(from, op_file, target)
   File.unlink(tmp_file)
 end
 
-CMD_WRAPPER = <<-EOS
-@echo off
-if "%OS%"=="Windows_NT" goto WinNT
-<ruby> -x "<command>" %1 %2 %3 %4 %5 %6 %7 %8 %9
-goto done
-:WinNT
-<ruby> -x "<command>" %*
-goto done
-:done
-EOS
-
 check_prereqs
 prepare_installation
 

    

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

Reply via email to