puppetlabs/facter — pull request #100 by joshcooper (2011-11-16 18:39:22+00:00)
Title: (#10885) Malformed facter.bat when ruby path contains backreferences

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.