Commit 85c65d3d by Jon Yurek

A real check for infinite loops in the :url interpolation.

parent 9223a917
...@@ -42,7 +42,7 @@ module Paperclip ...@@ -42,7 +42,7 @@ module Paperclip
# contains ":url" to prevent infinite recursion. This interpolation # contains ":url" to prevent infinite recursion. This interpolation
# is used in the default :path to ease default specifications. # is used in the default :path to ease default specifications.
def url attachment, style_name def url attachment, style_name
raise InfiniteInterpolationError if attachment.options[:url].include?(":url") raise InfiniteInterpolationError if caller.any?{|b| b.index("#{__FILE__}:#{__LINE__ + 1}") }
attachment.url(style_name, false) attachment.url(style_name, false)
end end
......
...@@ -144,7 +144,6 @@ module Paperclip ...@@ -144,7 +144,6 @@ module Paperclip
@s3_headers = @options[:s3_headers] || {} @s3_headers = @options[:s3_headers] || {}
@s3_host_alias = @options[:s3_host_alias] @s3_host_alias = @options[:s3_host_alias]
unless @url.to_s.match(/^:s3.*url$/) unless @url.to_s.match(/^:s3.*url$/)
@path = @url
@url = ":s3_path_url" @url = ":s3_path_url"
end end
AWS::S3::Base.establish_connection!( @s3_options.merge( AWS::S3::Base.establish_connection!( @s3_options.merge(
......
...@@ -82,14 +82,17 @@ class InterpolationsTest < Test::Unit::TestCase ...@@ -82,14 +82,17 @@ class InterpolationsTest < Test::Unit::TestCase
should "reinterpolate :url" do should "reinterpolate :url" do
attachment = mock attachment = mock
attachment.expects(:options).returns({:url => ":id"})
attachment.expects(:url).with(:style, false).returns("1234") attachment.expects(:url).with(:style, false).returns("1234")
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style) assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
end end
should "raise if infinite loop detcted reinterpolating :url" do should "raise if infinite loop detcted reinterpolating :url" do
attachment = mock attachment = Object.new
attachment.expects(:options).returns({:url => ":url"}) class << attachment
def url(*args)
Paperclip::Interpolations.url(self, :style)
end
end
assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) } assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
end end
......
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