Skip to content

Instantly share code, notes, and snippets.

@jinze
Created January 12, 2012 14:54
Show Gist options
  • Save jinze/1600958 to your computer and use it in GitHub Desktop.
Save jinze/1600958 to your computer and use it in GitHub Desktop.
A test for uglifier encoding Chinese bug
alert("ÖÐÎÄ");
# encoding: UTF-8
# A test for uglifier encoding Chinese bug
# author jinze@corp.netease.com
# at least need JRuby 1.6.5 && JRUBY_OPTS="--1.9"
$KCODE = 'UTF8'
require "rubygems"
require "uglifier"
require "multi_json"
ExecJS.runtime = ExecJS::Runtimes::Node #need NodeJS
#MultiJson.engine = :json_gem #(encode bug)
#MultiJson.engine = :ok_json #(encode bug, defalut but slow?)
#MultiJson.engine = :yajl #(encode bug, can not run under JRuby 1.6.4)
MultiJson.engine = :json_pure #(a little slow...but encode right!)
SRC_ENCODING = 'gb18030'
task :chinese do
str = '{"chinese":"中文"}'
puts str
puts MultiJson.encode(MultiJson.decode(str))
File.open("chinese_r.js", 'w') do |file|
file << str
result = File.read("chinese.js").encode('utf-8',SRC_ENCODING)
puts result
puts result.encoding
file << result
result2 = result.encode(SRC_ENCODING)
puts result2
puts result2.encoding
file << result2
result = Uglifier.compile(result, :copyright => false)
puts result
puts result.encoding
file << result
result = result.encode(SRC_ENCODING)
puts result
puts result.encoding
file << result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment