mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Ensuring that generated Content-Type headers properly escape params.
This commit is contained in:
parent
43de6d2d8a
commit
7721545ff2
2 changed files with 27 additions and 1 deletions
|
@ -275,7 +275,10 @@ module Sinatra
|
||||||
params.delete :charset if mime_type.include? 'charset'
|
params.delete :charset if mime_type.include? 'charset'
|
||||||
unless params.empty?
|
unless params.empty?
|
||||||
mime_type << (mime_type.include?(';') ? ', ' : ';')
|
mime_type << (mime_type.include?(';') ? ', ' : ';')
|
||||||
mime_type << params.map { |kv| kv.join('=') }.join(', ')
|
mime_type << params.map do |key, val|
|
||||||
|
val = val.inspect if val =~ /[";,]/
|
||||||
|
"#{key}=#{val}"
|
||||||
|
end.join(', ')
|
||||||
end
|
end
|
||||||
response['Content-Type'] = mime_type
|
response['Content-Type'] = mime_type
|
||||||
end
|
end
|
||||||
|
|
|
@ -586,6 +586,29 @@ class HelpersTest < Test::Unit::TestCase
|
||||||
get '/'
|
get '/'
|
||||||
assert_equal 'text/plain;charset=utf-16', response['Content-Type']
|
assert_equal 'text/plain;charset=utf-16', response['Content-Type']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'properly encodes parameters with delimiter characters' do
|
||||||
|
mock_app do
|
||||||
|
before '/comma' do
|
||||||
|
content_type 'image/png', :comment => 'Hello, world!'
|
||||||
|
end
|
||||||
|
before '/semicolon' do
|
||||||
|
content_type 'image/png', :comment => 'semi;colon'
|
||||||
|
end
|
||||||
|
before '/quote' do
|
||||||
|
content_type 'image/png', :comment => '"Whatever."'
|
||||||
|
end
|
||||||
|
|
||||||
|
get('*') { 'ok' }
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/comma'
|
||||||
|
assert_equal 'image/png;comment="Hello, world!"', response['Content-Type']
|
||||||
|
get '/semicolon'
|
||||||
|
assert_equal 'image/png;comment="semi;colon"', response['Content-Type']
|
||||||
|
get '/quote'
|
||||||
|
assert_equal 'image/png;comment="\"Whatever.\""', response['Content-Type']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'attachment' do
|
describe 'attachment' do
|
||||||
|
|
Loading…
Reference in a new issue