Skip to content

Remove downcase! method from sanitize function in ContentTypeField #1399

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/mail/fields/content_type_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ def sanitize(val)
gsub(/[; ]+/, '; '). #use '; ' as a separator (or EOL)
gsub(/;\s*$/,'') #remove trailing to keep examples below

if val =~ /(boundary=(\S*))/i
val = "#{$`.downcase}boundary=#{$2}#{$'.downcase}"
else
val.downcase!
end

case
when val.chomp =~ /^\s*([\w\-]+)\/([\w\-]+)\s*;\s?(ISO[\w\-]+)$/i
# Microsoft helper:
Expand Down
9 changes: 7 additions & 2 deletions spec/mail/fields/content_type_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@
it "should handle 'text/plain;ISO-8559-1'" do
c = Mail::ContentTypeField.new('text/plain;ISO-8559-1')
expect(c.string).to eq 'text/plain'
expect(c.parameters['charset']).to eq 'iso-8559-1'
expect(c.parameters['charset']).to eq 'ISO-8559-1'
end

it "should handle 'text/plain; charset = \"iso-8859-1\"'" do
Expand All @@ -726,7 +726,7 @@
it 'should handle text/html; charset="charset="GB2312""' do
c = Mail::ContentTypeField.new('text/html; charset="charset="GB2312""')
expect(c.string).to eq 'text/html'
expect(c.parameters['charset']).to eq 'gb2312'
expect(c.parameters['charset']).to eq 'GB2312'
end

it "should handle application/octet-stream; name=archiveshelp1[1].htm" do
Expand Down Expand Up @@ -769,6 +769,11 @@
expect(c.parameters['boundary']).to eq 'boundary123?WUT'
end

it "should preserve encoding of filenames" do
c = Mail::ContentTypeField.new('Content-Type: application/pdf; name==?utf-8?B?RXhhbXBsZS5wZGY=?=')
expect(c.string).to eq 'application/pdf'
expect(c.parameters['name']).to eq '=?utf-8?B?RXhhbXBsZS5wZGY=?='
end
end

end