Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Changed interpolations to run longer-named ones first, preventing col…
Browse files Browse the repository at this point in the history
…lisions.
  • Loading branch information
Jon Yurek committed Apr 23, 2008
1 parent 87bd86c commit f0cd9ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ def post_process #:nodoc:
end

def interpolate pattern, style = default_style #:nodoc:
pattern = pattern.dup
self.class.interpolations.each do |tag, l|
pattern.gsub!(/:\b#{tag}\b/) do |match|
l.call( self, style )
interpolations = self.class.interpolations.sort{|a,b| a.first.to_s <=> b.first.to_s }
interpolations.reverse.inject( pattern.dup ) do |result, interpolation|
tag, blk = interpolation
result.gsub(/:#{tag}/) do |match|
blk.call( self, style )
end
end
pattern
end

def queue_existing_for_delete #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion test/test_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AttachmentTest < Test::Unit::TestCase
end

should "make sure that they are interpolated correctly" do
assert_equal "1024.omg/1024-bbq/:idwhat/000/001/024.wtf", @dummy.avatar.path
assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path
end
end

Expand Down

0 comments on commit f0cd9ea

Please sign in to comment.