utf-8 support in both ruby 1.9 and 1.8

This commit is contained in:
Emi Matchu 2011-06-04 18:40:15 -04:00
parent 3db7e7c7b2
commit cf94c7ef59
7 changed files with 37 additions and 15 deletions

View file

@ -29,6 +29,8 @@ gem 'resque', '~> 1.15.0'
gem 'right_aws', '~> 2.1.0' gem 'right_aws', '~> 2.1.0'
gem "character-encodings", "~> 0.4.1", :platforms => :ruby_18
group :development_async do group :development_async do
# async wrappers # async wrappers
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git' gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'

View file

@ -74,6 +74,7 @@ GEM
arel (2.0.8) arel (2.0.8)
bcrypt-ruby (2.1.4) bcrypt-ruby (2.1.4)
builder (2.1.2) builder (2.1.2)
character-encodings (0.4.1)
closure-compiler (1.0.0) closure-compiler (1.0.0)
compass (0.10.6) compass (0.10.6)
haml (>= 3.0.4) haml (>= 3.0.4)
@ -179,6 +180,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
RocketAMF! RocketAMF!
addressable addressable
character-encodings (~> 0.4.1)
compass (~> 0.10.1) compass (~> 0.10.1)
devise (~> 1.1.5) devise (~> 1.1.5)
em-http-request! em-http-request!

View file

@ -1,5 +1,6 @@
require 'fileutils' require 'fileutils'
require 'uri' require 'uri'
require 'utf8'
class SwfAsset < ActiveRecord::Base class SwfAsset < ActiveRecord::Base
PUBLIC_ASSET_DIR = File.join('swfs', 'outfit') PUBLIC_ASSET_DIR = File.join('swfs', 'outfit')
@ -177,7 +178,7 @@ class SwfAsset < ActiveRecord::Base
if response.is_a? Net::HTTPSuccess if response.is_a? Net::HTTPSuccess
new_local_path = File.join(LOCAL_ASSET_DIR, local_path_within_outfit_swfs) new_local_path = File.join(LOCAL_ASSET_DIR, local_path_within_outfit_swfs)
new_local_dir = File.dirname new_local_path new_local_dir = File.dirname new_local_path
content = response.body.force_encoding 'utf-8' content = +response.body
FileUtils.mkdir_p new_local_dir FileUtils.mkdir_p new_local_dir
File.open(new_local_path, 'w') do |f| File.open(new_local_path, 'w') do |f|
f.print content f.print content

View file

@ -1,6 +1,7 @@
require 'active_support/core_ext/hash' require 'active_support/core_ext/hash'
require 'msgpack' require 'msgpack'
require 'openneo-auth-signatory' require 'openneo-auth-signatory'
require 'utf8'
module Openneo module Openneo
module Auth module Auth
@ -11,9 +12,10 @@ module Openneo
attr_writer :id attr_writer :id
def save! def save!
content = +MessagePack.pack(@message)
FileUtils.mkdir_p TMP_STORAGE_DIR FileUtils.mkdir_p TMP_STORAGE_DIR
File.open(tmp_storage_path, 'w') do |file| File.open(tmp_storage_path, 'w') do |file|
file.write MessagePack.pack(@message).force_encoding('utf-8') file.write content
end end
end end
@ -33,7 +35,8 @@ module Openneo
raise "Must set config.secret to the remote auth server's secret" raise "Must set config.secret to the remote auth server's secret"
end end
given_signature = params['signature'] given_signature = params['signature']
signatory = Auth::Signatory.new(Auth.config.secret.force_encoding('utf-8')) secret = +Auth.config.secret
signatory = Auth::Signatory.new(secret)
REMOTE_MSG_KEYS.each do |key| REMOTE_MSG_KEYS.each do |key|
unless params.include?(key) unless params.include?(key)
raise MissingParam, "Missing required param #{key.inspect}" raise MissingParam, "Missing required param #{key.inspect}"
@ -82,3 +85,4 @@ module Openneo
end end
end end
end end

13
lib/utf8.rb Normal file
View file

@ -0,0 +1,13 @@
if String.method_defined?(:force_encoding)
# UTF-8 support is native, so let's route the +"abc" syntax to the native
# encode method.
class String
def +@
force_encoding('utf-8')
end
end
else
require 'encoding/character/utf-8'
end

0
tmp/restart.txt Normal file
View file

Binary file not shown.