Created
January 12, 2012 14:54
-
-
Save jinze/1600958 to your computer and use it in GitHub Desktop.
A test for uglifier encoding Chinese bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert("ÖÐÎÄ"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# A test for uglifier encoding Chinese bug | |
# author [email protected] | |
# 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