Skip to content

Commit

Permalink
A real check for infinite loops in the :url interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jul 28, 2010
1 parent 9223a91 commit 85c65d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def filename attachment, style_name
# 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

Expand Down
1 change: 0 additions & 1 deletion lib/paperclip/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def self.extended base
@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(
Expand Down
9 changes: 6 additions & 3 deletions test/interpolations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 85c65d3

Please sign in to comment.