File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -64,12 +64,13 @@ def location=(url) headers['Location'] = url end
64
64
# the character set information will also be included in the content type
65
65
# information.
66
66
def content_type = ( mime_type )
67
- self . headers [ "Content-Type" ] =
67
+ new_content_type =
68
68
if mime_type =~ /charset/ || ( c = charset ) . nil?
69
69
mime_type . to_s
70
70
else
71
71
"#{ mime_type } ; charset=#{ c } "
72
72
end
73
+ self . headers [ "Content-Type" ] = URI . escape ( new_content_type , "\r \n " )
73
74
end
74
75
75
76
# Returns the response's content MIME type, or nil if content type has been set.
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ def render_default_content_types_for_respond_to
46
46
format . rss { render :text => "hello world!" , :content_type => Mime ::XML }
47
47
end
48
48
end
49
+
50
+ def render_content_type_from_user_input
51
+ response . content_type = params [ :hello ]
52
+ render :text => "hello"
53
+ end
49
54
50
55
def rescue_action ( e ) raise end
51
56
end
@@ -129,6 +134,11 @@ def test_change_for_rxml
129
134
assert_equal Mime ::HTML , @response . content_type
130
135
assert_equal "utf-8" , @response . charset
131
136
end
137
+
138
+ def test_user_supplied_value
139
+ get :render_content_type_from_user_input , :hello => "hello/world\r \n Attack: true"
140
+ assert_equal "hello/world%0D%0AAttack: true" , @response . content_type
141
+ end
132
142
end
133
143
134
144
class AcceptBasedContentTypeTest < ActionController ::TestCase
You can’t perform that action at this time.
0 commit comments