Skip to content
Browse files

correctly escape windows reserved shell characters

Cope with @binary with values such as:
  C:\Windows\System32\cscript.exe //E:jscript //Nologo //U
  • Loading branch information...
1 parent 1332be0 commit a7cdbfc0c1c89b6b2570f74673b4aceffe7c9d56 @rubys committed
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/execjs/external_runtime.rb
View
5 lib/execjs/external_runtime.rb
@@ -122,7 +122,7 @@ def runner_source
end
def exec_runtime(filename)
- output = sh("#{shell_escape(@binary, filename)} 2>&1")
+ output = sh("#{shell_escape(*(@binary.split(' ') << filename))} 2>&1")
if $?.success?
output
else
@@ -182,7 +182,8 @@ def sh(command)
if ExecJS.windows?
def shell_escape(*args)
- args.map { |arg| arg.inspect }.join(" ")
+ # see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
+ args.map { |arg| arg.gsub(/([&|()<>^ "])/,'^\1') }.join(" ")
end
else
def shell_escape(*args)

0 comments on commit a7cdbfc

Please sign in to comment.
Something went wrong with that request. Please try again.