Commit cc89e4aa by Iain Beeston Committed by Iain Beeston

Escaped strings that are inserted into regexps during interpolation

parent 7f523e35
......@@ -86,7 +86,7 @@ module Paperclip
# 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"
......
......@@ -154,6 +154,13 @@ class InterpolationsTest < Test::Unit::TestCase
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment