Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iainbeeston/paperclip
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Oct 5, 2011
2 parents eadf7e8 + cc89e4a commit 85936c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/interpolations.rb
Expand Up @@ -86,7 +86,7 @@ def class attachment = nil, style_name = nil

# Returns the basename of the file. e.g. "file" for "file.jpg"
def basename attachment, style_name
attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "")
attachment.original_filename.gsub(/#{Regexp.escape(File.extname(attachment.original_filename))}$/, "")
end

# Returns the extension of the file. e.g. "jpg" for "file.jpg"
Expand Down
7 changes: 7 additions & 0 deletions test/interpolations_test.rb
Expand Up @@ -154,6 +154,13 @@ def url(*args)
attachment.stubs(:original_filename).returns("one")
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
end

should "return the basename when the extension contains regexp special characters" do
attachment = mock
attachment.stubs(:styles).returns({})
attachment.stubs(:original_filename).returns("one.ab)")
assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
end

should "return the timestamp" do
now = Time.now
Expand Down

0 comments on commit 85936c7

Please sign in to comment.