Commit 784717b8 by Prem Sichanugrist

Fix a potential bug when user turn on AWS logging

This should fix an error when the user has turn on AWS logging while
and upload a file with non-English filename, as `aws-sdk` logger is not
encoding aware.

The problem was that the string returned from another logger methods
is in `US-ASCII`, while the string returned from Paperclip would be in
`UTF-8`. When the logger calls `#join` on those strings, Ruby would
raise an exception.

This solution is not the best, as it involves a monkey-patching, but
should make sure that the upload goes through without any hiccup. For
the long run, I'm going to send a patch to `aws-sdk` and also make
Paperclip require at least `aws-sdk > 1.4.1`
parent 55c686dc
......@@ -85,6 +85,21 @@ module Paperclip
def self.extended base
begin
require 'aws-sdk'
# Overriding AWS::Core::LogFormatter to make sure it return a UTF-8 string
if AWS::VERSION >= "1.3.9"
AWS::Core::LogFormatter.class_eval do
def summarize_hash(hash)
hash.map { |key, value| ":#{key}=>#{summarize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
end
end
else
AWS::Core::ClientLogging.class_eval do
def sanitize_hash(hash)
hash.map { |key, value| "#{sanitize_value(key)}=>#{sanitize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
end
end
end
rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)"
raise e
......
# encoding: utf-8
require './test/helper'
require 'open-uri'
......@@ -635,6 +637,18 @@ class IntegrationTest < Test::Unit::TestCase
headers = s3_headers_for(@dummy.avatar, :original)
assert_equal 'image/png', headers['content-type']
end
context "with non-english character in the file name" do
setup do
@file.stubs(:original_filename).returns("クリップ.png")
@dummy.avatar = @file
end
should "not raise any error" do
@dummy.save!
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment