Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Attaching a file with quotes in the name doesn't work #14158

wants to merge 1 commit into from

4 participants


Here's a failing spec that demonstrates this case.

Expected behavior: Either the file is attached with the quotes properly escaped in the Content-Disposition, or an exception is thrown.
Actual behavior: The attachment is not added to the attachments list.

I'm not sure how best to fix this, but this test case should at least isolate the problem.



Your beef lies with the mail gem, probably somewhere in this file:

ActionMailer is just a wrapper around it.


I'll take a look if I can fix this. (unless you wanted to fix this - I first red that you just wanted to provide the failing test...)

Edit: I have almost fixed this...
It seems that modifying it here: fixes it (but introduces new errors)

@jeremy jeremy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2014
  1. @raindrift
This page is out of date. Refresh to see the latest.
7 actionmailer/test/base_test.rb
@@ -100,6 +100,13 @@ def teardown
assert_equal('This is test File content', email.attachments['invoice.pdf'].decoded)
+ test "attachment with content and a filename with quotes" do
+ email = BaseMailer.attachment_with_quotes_in_filename
+ assert_equal(1, email.attachments.length)
+ assert_equal('invoice "for you".pdf', email.attachments[0].filename)
+ assert_equal('This is test File content', email.attachments['invoice "for you".pdf'].decoded)
+ end
test "attachment gets content type from filename" do
email = BaseMailer.attachment_with_content
assert_equal('invoice.pdf', email.attachments[0].filename)
1  actionmailer/test/fixtures/base_mailer/attachment_with_quotes_in_filename.erb
@@ -0,0 +1 @@
+Attachment with quotes in its filename
5 actionmailer/test/mailers/base_mailer.rb
@@ -37,6 +37,11 @@ def attachment_with_content(hash = {})
+ def attachment_with_quotes_in_filename(hash = {})
+ attachments['invoice "for you".pdf'] = 'This is test File content'
+ mail(hash)
+ end
def attachment_with_hash
attachments['invoice.jpg'] = { data: ::Base64.encode64("\312\213\254\232)b"),
mime_type: "image/x-jpg",
Something went wrong with that request. Please try again.