Skip to content

Commit

Permalink
update filename attachment to write all non word and periods to under…
Browse files Browse the repository at this point in the history
…scores
  • Loading branch information
phallstrom committed Apr 11, 2013
1 parent e0452c2 commit bfee5d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/letter_opener/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def render
attachments_dir = File.join(@location, 'attachments')
FileUtils.mkdir_p(attachments_dir)
mail.attachments.each do |attachment|
filename = attachment.filename.gsub(File::SEPARATOR, File::PATH_SEPARATOR)
filename = attachment.filename.gsub(/[^\w.]/, '_')
path = File.join(attachments_dir, filename)

unless File.exists?(path) # true if other parts have already been rendered
Expand Down
8 changes: 4 additions & 4 deletions spec/letter_opener/delivery_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
end
end

context 'attachments on with forward slashes in the filename' do
context 'attachments with non-word characters in the filename' do
before do
Mail.deliver do
from 'foo@example.com'
Expand All @@ -234,18 +234,18 @@
text_part do
body 'This is <plain> text'
end
attachments['slashes/colons.txt'] = File.read(__FILE__)
attachments['non word:chars/used,01.txt'] = File.read(__FILE__)
end
end

it 'creates attachments dir with attachment' do
attachment = Dir["#{location}/*/attachments/slashes:colons.txt"].first
attachment = Dir["#{location}/*/attachments/non_word_chars_used_01.txt"].first
File.exists?(attachment).should be_true
end

it 'saves attachment name' do
plain = File.read(Dir["#{location}/*/plain.html"].first)
plain.should include('slashes:colons.txt')
plain.should include('non_word_chars_used_01.txt')
end
end

Expand Down

0 comments on commit bfee5d8

Please sign in to comment.