Skip to content

Commit

Permalink
Rack::Request#media_type is available now
Browse files Browse the repository at this point in the history
  • Loading branch information
hibariya committed Dec 18, 2023
1 parent 402512e commit e8111c5
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/rack/utf8_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,11 @@ def build_strategy(options)
end

def sanitize_rack_input(env)
# https://github.com/rack/rack/blob/master/lib/rack/request.rb#L42
# Logic borrowed from Rack::Request#media_type,#media_type_params,#content_charset
# Ignoring charset in content type.
if content_type = env['CONTENT_TYPE']
content_type = content_type.split(/[;,]/, 2).first
if content_type
content_type.strip!
content_type.downcase!
end
end
request = Rack::Request.new(env)
content_type = request.media_type
return unless @sanitizable_content_types.any? {|type| content_type == type }

charset = Rack::Request.new(env).content_charset
charset = request.content_charset
return if charset && charset.downcase != 'utf-8'

uri_encoded = URI_ENCODED_CONTENT_TYPES.any? {|type| content_type == type}
Expand Down

0 comments on commit e8111c5

Please sign in to comment.