Commit 85c65d3d by Jon Yurek

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

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