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

Commit

Permalink
CScript Unicode fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenet committed Sep 3, 2011
1 parent 9664391 commit adc3312
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/execjs/external_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def initialize(options)
@runner_path = options[:runner_path]
@test_args = options[:test_args]
@test_match = options[:test_match]
@encoding = options[:encoding]
@binary = locate_binary
end

Expand Down Expand Up @@ -120,7 +121,7 @@ def runner_source

def exec_runtime(filename)
output = nil
IO.popen("#{@binary} #{filename} 2>&1") { |f| output = f.read }
IO.popen("#{@binary} #{filename} 2>&1") { |f| output = fix_encoding(f.read) }
if $?.success?
output
else
Expand Down Expand Up @@ -154,5 +155,20 @@ def which(command)
end
nil
end

private

def fix_encoding(data)
return data unless @encoding

if data.respond_to?(:encode)
data.force_encoding(@encoding).encode('UTF-8')
else
require 'iconv'
ic = Iconv.new('UTF-8', @encoding)
ic.iconv(data)
end
end

end
end
5 changes: 3 additions & 2 deletions lib/execjs/runtimes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ module Runtimes

JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js"
:command => "cscript //E:jscript //Nologo //U",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
)


Expand Down

0 comments on commit adc3312

Please sign in to comment.