mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Handles Content-Type
strings that already contain parameters correctly in
`content_type` (example: `content_type "text/plain; charset=utf-16"`).
This commit is contained in:
parent
ec5f6064a1
commit
914db7eefe
3 changed files with 31 additions and 1 deletions
4
CHANGES
4
CHANGES
|
@ -36,6 +36,10 @@
|
|||
* URIs passed to the `url` helper or `redirect` may now use any schema to be
|
||||
identified as absolute URIs, not only `http` or `https`. (Konstantin Haase)
|
||||
|
||||
* Handles `Content-Type` strings that already contain parameters correctly in
|
||||
`content_type` (example: `content_type "text/plain; charset=utf-16"`).
|
||||
(Konstantin Haase)
|
||||
|
||||
= 1.2.1 / 2011-03-17
|
||||
|
||||
* Use a generated session secret when using `enable :sessions`. (Konstantin
|
||||
|
|
|
@ -181,7 +181,11 @@ module Sinatra
|
|||
unless params.include? :charset or settings.add_charset.all? { |p| not p === mime_type }
|
||||
params[:charset] = params.delete('charset') || settings.default_encoding
|
||||
end
|
||||
mime_type << ";#{params.map { |kv| kv.join('=') }.join(', ')}" unless params.empty?
|
||||
params.delete :charset if mime_type.include? 'charset'
|
||||
unless params.empty?
|
||||
mime_type << (mime_type.include?(';') ? ', ' : ';')
|
||||
mime_type << params.map { |kv| kv.join('=') }.join(', ')
|
||||
end
|
||||
response['Content-Type'] = mime_type
|
||||
end
|
||||
|
||||
|
|
|
@ -442,6 +442,28 @@ class HelpersTest < Test::Unit::TestCase
|
|||
get '/'
|
||||
assert tests_ran
|
||||
end
|
||||
|
||||
it 'handles already present params' do
|
||||
mock_app do
|
||||
get '/' do
|
||||
content_type 'foo/bar;level=1', :charset => 'utf-8'
|
||||
'ok'
|
||||
end
|
||||
end
|
||||
get '/'
|
||||
assert_equal 'foo/bar;level=1, charset=utf-8', response['Content-Type']
|
||||
end
|
||||
|
||||
it 'does not add charset if present' do
|
||||
mock_app do
|
||||
get '/' do
|
||||
content_type 'text/plain;charset=utf-16'
|
||||
'ok'
|
||||
end
|
||||
end
|
||||
get '/'
|
||||
assert_equal 'text/plain;charset=utf-16', response['Content-Type']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send_file' do
|
||||
|
|
Loading…
Reference in a new issue