Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Formatting and anchoring the extension gsub to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Nov 5, 2008
1 parent 7d29d06 commit 94eb291
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/paperclip/attachment.rb
Expand Up @@ -74,11 +74,11 @@ def assign uploaded_file
return nil if uploaded_file.nil? return nil if uploaded_file.nil?


logger.info("[paperclip] Writing attributes for #{name}") logger.info("[paperclip] Writing attributes for #{name}")
@queued_for_write[:original] = uploaded_file.to_tempfile @queued_for_write[:original] = uploaded_file.to_tempfile
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_')) instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_'))
instance_write(:content_type, uploaded_file.content_type.strip) instance_write(:content_type, uploaded_file.content_type.strip)
instance_write(:file_size, uploaded_file.size.to_i) instance_write(:file_size, uploaded_file.size.to_i)
instance_write(:updated_at, Time.now) instance_write(:updated_at, Time.now)


@dirty = true @dirty = true


Expand Down Expand Up @@ -169,7 +169,7 @@ def self.interpolations
attachment.instance.class.name.underscore.pluralize attachment.instance.class.name.underscore.pluralize
end, end,
:basename => lambda do |attachment,style| :basename => lambda do |attachment,style|
attachment.original_filename.gsub(File.extname(attachment.original_filename), "") attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "")
end, end,
:extension => lambda do |attachment,style| :extension => lambda do |attachment,style|
((style = attachment.styles[style]) && style.last) || ((style = attachment.styles[style]) && style.last) ||
Expand Down
1 change: 0 additions & 1 deletion test/attachment_test.rb
Expand Up @@ -174,7 +174,6 @@ class AttachmentTest < Test::Unit::TestCase
should "strip whitespace from content_type field" do should "strip whitespace from content_type field" do
assert_equal "image/png", @dummy.avatar.instance.avatar_content_type assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
end end

end end


context "Attachment with strange letters" do context "Attachment with strange letters" do
Expand Down

0 comments on commit 94eb291

Please sign in to comment.