Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary code for force_encoding #1527

Merged
merged 1 commit into from Apr 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 13 additions & 20 deletions lib/sinatra/base.rb
Expand Up @@ -1743,29 +1743,22 @@ def cleaned_caller(keep = 3)
end
end

# Fixes encoding issues by
# * defaulting to UTF-8
# * casting params to Encoding.default_external
#
# The latter might not be necessary if Rack handles it one day.
# Keep an eye on Rack's LH #100.
def force_encoding(*args) settings.force_encoding(*args) end
if defined? Encoding
def self.force_encoding(data, encoding = default_encoding)
return if data == settings || data.is_a?(Tempfile)
if data.respond_to? :force_encoding
data.force_encoding(encoding).encode!
elsif data.respond_to? :each_value
data.each_value { |v| force_encoding(v, encoding) }
elsif data.respond_to? :each
data.each { |v| force_encoding(v, encoding) }
end
data
# Force data to specified encoding. It defaults to settings.default_encoding
# which is UTF-8 by default
def self.force_encoding(data, encoding = default_encoding)
return if data == settings || data.is_a?(Tempfile)
if data.respond_to? :force_encoding
data.force_encoding(encoding).encode!
elsif data.respond_to? :each_value
data.each_value { |v| force_encoding(v, encoding) }
elsif data.respond_to? :each
data.each { |v| force_encoding(v, encoding) }
end
else
def self.force_encoding(data, *) data end
data
end

def force_encoding(*args) settings.force_encoding(*args) end

reset!

set :environment, (ENV['APP_ENV'] || ENV['RACK_ENV'] || :development).to_sym
Expand Down