Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoid setting Encoding.default_external and default_internal.

  • Loading branch information...
commit be53ce77052235e3b056a109561b1708facf4308 1 parent e93951e
@rkh rkh authored
Showing with 6 additions and 11 deletions.
  1. +1 −1  Rakefile
  2. +3 −9 lib/sinatra/base.rb
  3. +2 −1  test/encoding_test.rb
View
2  Rakefile
@@ -16,7 +16,7 @@ end
if !ENV['NO_TEST_FIX'] and RUBY_VERSION == '1.9.2' and RUBY_PATCHLEVEL == 0
# Avoids seg fault
task(:test) do
- second_run = %w[settings rdoc markaby templates static].map { |l| "test/#{l}_test.rb" }
+ second_run = %w[settings rdoc markaby templates static textile].map { |l| "test/#{l}_test.rb" }
first_run = Dir.glob('test/*_test.rb') - second_run
[first_run, second_run].each { |f| sh "testrb #{f.join ' '}" }
end
View
12 lib/sinatra/base.rb
@@ -130,8 +130,7 @@ def mime_type(type)
def content_type(type, params={})
mime_type = mime_type(type)
fail "Unknown media type: %p" % type if mime_type.nil?
- params[:charset] ||= params.delete('charset') ||
- defined?(Encoding) ? Encoding.default_external.to_s.downcase : 'utf-8'
+ params[:charset] ||= params.delete('charset') || settings.default_encoding
response['Content-Type'] = "#{mime_type};#{params.map { |kv| kv.join('=') }.join(', ')}"
end
@@ -1211,15 +1210,10 @@ def caller_locations
# The latter might not be necessary if Rack handles it one day.
# Keep an eye on Rack's LH #100.
if defined? Encoding
- if Encoding.default_external.to_s =~ /^ASCII/
- Encoding.default_external = "UTF-8"
- end
- Encoding.default_internal ||= Encoding.default_external
-
def force_encoding(data)
return if data == self || data.is_a?(Tempfile)
if data.respond_to? :force_encoding
- data.force_encoding(Encoding.default_external)
+ data.force_encoding settings.default_encoding
elsif data.respond_to? :each_value
data.each_value { |v| force_encoding(v) }
elsif data.respond_to? :each
@@ -1230,7 +1224,6 @@ def force_encoding(data)
def force_encoding(*) end
end
-
reset!
set :environment, (ENV['RACK_ENV'] || :development).to_sym
@@ -1240,6 +1233,7 @@ def force_encoding(*) end
set :sessions, false
set :logging, false
set :method_override, false
+ set :default_encoding, "utf-8"
class << self
alias_method :methodoverride?, :method_override?
View
3  test/encoding_test.rb
@@ -8,7 +8,8 @@ class BaseTest < Test::Unit::TestCase
end
it 'allows unicode strings in ascii templates per default (1.9)' do
- @base.new.haml(:ascii, {}, :value => "åkej")
+ next unless defined? Encoding
+ @base.new.haml(File.read(@base.views + "/ascii.haml").encode("ASCII"), {}, :value => "åkej")
end
it 'allows ascii strings in unicode templates per default (1.9)' do
Please sign in to comment.
Something went wrong with that request. Please try again.