documentcloud / jammit

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

compression fails when using javascript file containing utf-8 characters #91

Closed ghost closed 13 years ago

ghost commented 13 years ago

platform:

Compression of application.js file:

$(function() {
    var a = "ąść";
});

results in error (using YUI): YUI::Compressor::RuntimeError in JammitController#package compression failed

using Closure: Encoding::UndefinedConversionError in JammitController#package "\xC4" from ASCII-8BIT to UTF-8

Here is my assest.rb file: package_assets: always # (on, off, always) embed_assets: off # (on, off, datauri) compress_assets: on # (on, off) gzip_assets: on # (on, off) template_function: on # (defaults to the built-in micro-templating) package_path: packages # (defaults to assets) javascript_compressor: closure # (yui, closure)

javascripts:
  workspace:
    - public/javascripts/application.js

stylesheets:
  workspace:
    - public/stylesheets/*.css
jfturcot commented 13 years ago

I also have the exact same problem under ruby 1.9.2, rails 3.0.1 and jammit 0.5.4 with a similar assets.yml file. Did anyone find a solution to this problem? Thanks.

agibralter commented 13 years ago

Does it work with different accented characters? é?

ghost commented 13 years ago

jfturcot: change all special characters to corresponding html entities (using e.g this page http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct&unicodeinhtml=dec&htmlent=1). This will solve the problem.

jfturcot commented 13 years ago

It did solve it, thanks a lot!

hemju commented 13 years ago

I have the same problem, but I can't find the non-ascii char. I looked at all files, I also wrote a small script to check it. Anyone any idea how I can find the non-ascii char?

Btw. this issue is still open, does this mean this is a real bug (which I think it is) or is it just not closed yet?

outerim commented 13 years ago

Anyone working on this? I'm having the same problem.

larskuhnt commented 13 years ago

I had the same issue and fixed it by forcing the encoding of the compressed string to BINARY:

https://github.com/larskuhnt/jammit/commit/67e535cf6495542118c812c8feec4fe750088b91

christoffer commented 13 years ago

I had this problem too (rails 3.0.1, ruby 1.9.2, jammit 0.5.4), and unfortunately larskuhnt's fix did not solve it for me.

However, using the patched yui-compressor from boof (adds a single line) did.

jashkenas commented 13 years ago

I'm afraid this looks like an issue with the yui-compressor gem. There was just a new version released recently. I'd recommend trying to install that -- and if it still isn't working for you, opening a ticket over here:

https://github.com/sstephenson/ruby-yui-compressor/issues

rhuelga commented 13 years ago

In my case it's not a problem with yui-compressor gem. I'm getting the same issue described above, but if I run jammit from the command line everything works OK, and I get the correct files on the public/assets with the correct utf-8 characters.

jammit 0.6.0 yu-compressor 0.9.3

agibralter commented 13 years ago

Hmm did you restart your server/load the latest gems? I find it hard to imagine that the same version of Jammit would give you the error in one place but not the other.

rhuelga commented 13 years ago

I have try it again restarting the server, and works the same way. if I run jammit from the command line no problem. I delete the public/assets and try from the browser and I get:

YUI::Compressor::RuntimeError in JammitController#package compression failed

agibralter commented 13 years ago

Have you deleted previous versions of yui-compressor and jammit on your system?

rhuelga commented 13 years ago

There isn't previous versions, I'm starting with YUI and jammit today I'm on OsX, maybe it will help.

oleander commented 13 years ago

I solved it by using the tip from christoffer.

I added this line below to my Gemfile. The line has to be placed above gem 'jammit' for it to work.

gem 'yui-compressor', :git => "git://github.com/oleander/ruby-yui-compressor.git", :require  => "yui/compressor"

I merged the official ruby-yui-compressor with the one christoffer linked to, patched yui-compressor from boof.

Just using the patched yui-compressor from boof fork did not work. I got this error when trying to used it.

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:20)
Caused by: java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
at com.yahoo.platform.yui.compressor.CssCompressor.compress(CssCompressor.java:86)
at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:178)
... 5 more

This only works when using the yui compressor, with package_assets: yes at the top of the assets.yaml file.

bjensen commented 13 years ago

any upcoming release to fix this issue?

oleander commented 13 years ago

@pointman Try my solution, it worked.

webmat commented 13 years ago

Hey guys, for what it's worth, I just had, and fixed a similar problem. Turns out the cause was a misused reserved word, not a special character.

The function declaration "function(size, class)" was causing that because of the word "class". Just renaming it to something else , e.g. "function(size, klass)", or removing altogether , e.g. "function(size)", fixes the problem :-)

So before resorting to a patch that modifies a gem, look for misused reserved words in your code https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words

agibralter commented 13 years ago

Yeah, it's kind of annoying that the yui-compressor gem doesn't relay the error output from running the java app... I was using float as an object property in a jQuery $.fn.css({...}) call without quotes... I needed {"float":"left"}. It took me... HOURS to figure out what was going on. Another one that got me was char as a variable name.

jorgemanrubia commented 13 years ago

@webmat I had exactly the same problem that you described. I wonder how long it would have take me to discover it without your comment. Thanks!

dereckrx commented 12 years ago

I had this issue, only it was caused by an invalid css file. I ran a css validator on all the updated files and found the problem. Everything seemed to work after that. So, by the look of this thread, it seems this issue (so far) can be caused by:

webmat commented 11 years ago

Jeez, I had a similar problem again, but this time my last comment ^ didn't do it.

What fixed it was to prepend "LANG=en_US.UTF-8" to bundle exec jammit... Running in Capistrano, it didn't seem to pick up that config from the .bash_profile.