Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Header encoding should be US-ASCII, not the default external encoding

  • Loading branch information...
commit e20f93af966d24017ecccbfd035c12afc12c802e 1 parent ece27b6
@jeremy jeremy authored
View
1  CHANGELOG.rdoc
@@ -12,6 +12,7 @@ Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
Bugs:
+* Header encoding should be US-ASCII, not the default external encoding (jeremy)
* Address elements should return decoded display names by default (jeremy)
* Fix up tests that depend on utf-8 external encoding; read fixtures as binary (jeremy)
* Capture stderr from Sendmail and Exim deliveries (jeremy)
View
1  lib/mail/header.rb
@@ -201,6 +201,7 @@ def charset=(val)
def encoded
buffer = ''
+ buffer.force_encoding('us-ascii') if buffer.respond_to?(:force_encoding)
fields.each do |field|
buffer << field.encoded
end
View
8 spec/mail/header_spec.rb
@@ -545,9 +545,13 @@
describe "encoding" do
it "should output a parsed version of itself to US-ASCII on encoded and tidy up and sort correctly" do
- header = Mail::Header.new("To: Mikel\r\n\sLindsaar <mikel@test.lindsaar.net>\r\nFrom: bob\r\n\s<bob@test.lindsaar.net>\r\nSubject: This is\r\n a long\r\n\s \t \t \t badly formatted \r\n \t\t \t field")
+ encoded = Mail::Header.new("To: Mikel\r\n\sLindsaar <mikel@test.lindsaar.net>\r\nFrom: bob\r\n\s<bob@test.lindsaar.net>\r\nSubject: This is\r\n a long\r\n\s \t \t \t badly formatted \r\n \t\t \t field").encoded
result = "From: bob <bob@test.lindsaar.net>\r\nTo: Mikel Lindsaar <mikel@test.lindsaar.net>\r\nSubject: This is a long badly formatted field\r\n"
- header.encoded.should eq result
+ if result.respond_to?(:encode!)
+ result.encode!(Encoding::US_ASCII)
+ encoded.encoding.should eq Encoding::US_ASCII if encoded.respond_to?(:encoding)
+ end
+ encoded.should eq result
end
end

0 comments on commit e20f93a

Please sign in to comment.
Something went wrong with that request. Please try again.