documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.io/jammit/
MIT License
1.16k stars 197 forks source link

Encoding error with utf-8 js file #198

Closed archiloque closed 13 years ago

archiloque commented 13 years ago

When trying to use jammit on some js files using utf-8 encoding like sproutcore

/Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/multi_json-1.0.3/lib/multi_json/engines/json_gem.rb:17:in `encode': "\xC2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/multi_json-1.0.3/lib/multi_json/engines/json_gem.rb:17:in `to_json'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/multi_json-1.0.3/lib/multi_json/engines/json_gem.rb:17:in `encode'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/multi_json-1.0.3/lib/multi_json.rb:72:in `encode'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/uglifier-1.0.1/lib/uglifier.rb:63:in `compile'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/compressor.rb:74:in `compress_js'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/packager.rb:85:in `pack_javascripts'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/packager.rb:41:in `block in precache_all'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/packager.rb:41:in `each'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/packager.rb:41:in `precache_all'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit.rb:132:in `package!'
from /Users/archiloque/.rvm/gems/ruby-1.9.2-p290/gems/jammit-0.6.3/lib/jammit/command_line

to fix it ,I'vre rewritten Jammit::Compressor#read_binary_file so the css and js files are read as UTF-8 instead of binary

# `File.read`, but in "binary" mode for non js and non css scripts
def read_binary_file(path)
  if ['.css', '.js'].include? File.extname(path)
    File.open(path, 'r:UTF-8') {|f| f.read }
  else
    File.open(path, 'rb') {|f| f.read }
  end
end
fabrikagency commented 13 years ago

Is there a pull request for this already out there? This fixed a problem for me as well when passing to the closure compiler gem. I can create one if needed.

mromulus commented 13 years ago

I'm having the same issue - please do a pull request if you can