Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Use quoting rather than shellescape to give Windows compatibility #216

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
27 changes: 27 additions & 0 deletions lib/ridley/chef/cookbook/syntax_check.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
require 'erubis'
require 'rbconfig'

if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
require 'win32api'
end

module Ridley::Chef
class Cookbook
Expand Down Expand Up @@ -206,3 +211,25 @@ def invalid_ruby_file(ruby_file, error_message)
end
end
end

module Shellwords
def get_short_win32_filename(long_name)
win_func = Win32API.new("kernel32","GetShortPathName","PPL"," L")
buf = 0.chr * 256
buf[0..long_name.length-1] = long_name
win_func.call(long_name, buf, buf.length)
return buf.split(0.chr).first
end

module_function :get_short_win32_filename
end

class String
def shellescape
if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Shellwords.get_short_win32_filename(self)
else
Shellwords.escape(self)
end
end
end