execjs 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,8 +21,9 @@ module ExecJS
21
21
 
22
22
  def exec(source, options = {})
23
23
  source = source.encode('UTF-8') if source.respond_to?(:encode)
24
+ source = "#{@source}\n#{source}" if @source
24
25
 
25
- compile_to_tempfile([@source, source].join("\n")) do |file|
26
+ compile_to_tempfile(source) do |file|
26
27
  extract_result(@runtime.send(:exec_runtime, file.path))
27
28
  end
28
29
  end
@@ -121,7 +122,7 @@ module ExecJS
121
122
  end
122
123
 
123
124
  def exec_runtime(filename)
124
- output = sh("#{Shellwords.join([@binary, filename])} 2>&1")
125
+ output = sh("#{shell_escape(*(@binary.split(' ') << filename))} 2>&1")
125
126
  if $?.success?
126
127
  output
127
128
  else
@@ -132,7 +133,7 @@ module ExecJS
132
133
  def locate_binary
133
134
  if binary = which(@command)
134
135
  if @test_args
135
- output = `#{Shellwords.join([binary, @test_args])} 2>&1`
136
+ output = `#{shell_escape(binary, @test_args)} 2>&1`
136
137
  binary if output.match(@test_match)
137
138
  else
138
139
  binary
@@ -144,9 +145,9 @@ module ExecJS
144
145
  Array(command).each do |name|
145
146
  name, args = name.split(/\s+/, 2)
146
147
  result = if ExecJS.windows?
147
- `#{Shellwords.join(["#{ExecJS.root}/support/which.bat", name])}`
148
+ `#{shell_escape("#{ExecJS.root}/support/which.bat", name)}`
148
149
  else
149
- `#{Shellwords.join(['command', '-v', name])} 2>/dev/null`
150
+ `#{shell_escape('command', '-v', name)} 2>/dev/null`
150
151
  end
151
152
 
152
153
  if path = result.strip.split("\n").first
@@ -178,5 +179,16 @@ module ExecJS
178
179
  end
179
180
  end
180
181
  end
182
+
183
+ if ExecJS.windows?
184
+ def shell_escape(*args)
185
+ # see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
186
+ args.map { |arg| arg.gsub(/([&|()<>^ "])/,'^\1') }.join(" ")
187
+ end
188
+ else
189
+ def shell_escape(*args)
190
+ Shellwords.join(args)
191
+ end
192
+ end
181
193
  end
182
194
  end
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "1.2.7"
2
+ VERSION = "1.2.8"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 7
10
- version: 1.2.7
9
+ - 8
10
+ version: 1.2.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-19 00:00:00 -05:00
19
+ date: 2011-09-20 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  requirements: []
163
163
 
164
164
  rubyforge_project:
165
- rubygems_version: 1.6.2
165
+ rubygems_version: 1.5.2
166
166
  signing_key:
167
167
  specification_version: 3
168
168
  summary: Run JavaScript code from Ruby