documentcloud / jammit

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

Problem with encoding base64 on 1.9 #100

Closed syrm closed 13 years ago

syrm commented 13 years ago

Hello,

The encoding in base64 is wrong on 1.9 You should use in compressor.rb line 247 : File.open(path, 'rb') {|f| f.read } Instead of : File.open(path, 'r:binary') {|f| f.read }

Thanks

jashkenas commented 13 years ago

I thought that r:binary was the preferred encoding for 1.9 -- a 1.9 user submitted it in the first place. Can you shed any light on the issue?

syrm commented 13 years ago

Unfortunately i'm not an expert, but. The problem is only on windows not on linux

The reference : <?php file_put_contents("test_base64_php", base64_encode(file_get_contents("test.png")));

The both test files :

require 'base64'
data = File.open("test.png", 'rb') {|f| f.read }
w = File.open("test_base64_ruby", "w")
w.write(Base64.encode64(data).gsub(/\n/, ''))

and

require 'base64'
data = File.open("test.png", 'r:binary') {|f| f.read }
w = File.open("test_base64_binary_ruby", "w")
w.write(Base64.encode64(data).gsub(/\n/, ''))

On linux : dbb8d14de5d08a913456b627d0fb15d4 test_base64_php dbb8d14de5d08a913456b627d0fb15d4 test_base64_ruby dbb8d14de5d08a913456b627d0fb15d4 test_base64_binary_ruby

On windows : dbb8d14de5d08a913456b627d0fb15d4 test_base64_ruby 1638df64bcf94dc15668ad47f9ff7e20 test_base64_binary_ruby

So on windows r:binary doesn't work, but rb seems works in all case.

All test are with 1.9.2p0

jashkenas commented 13 years ago

Sure thing -- thanks for looking into it. Here's the patch:

https://github.com/documentcloud/jammit/commit/0a2e1a9888c32c53c396663adeb66bf28219fb25