Fixed: inline attached image should not match partial filename (#2683).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2363 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
4aa90cc072
commit
ff0c96011f
@ -357,16 +357,15 @@ module ApplicationHelper
|
|||||||
attachments = attachments.sort_by(&:created_on).reverse
|
attachments = attachments.sort_by(&:created_on).reverse
|
||||||
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
|
text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
|
||||||
style = $1
|
style = $1
|
||||||
filename = $6
|
filename = $6.downcase
|
||||||
rf = Regexp.new(Regexp.escape(filename), Regexp::IGNORECASE)
|
|
||||||
# search for the picture in attachments
|
# search for the picture in attachments
|
||||||
if found = attachments.detect { |att| att.filename =~ rf }
|
if found = attachments.detect { |att| att.filename.downcase == filename }
|
||||||
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
||||||
desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
|
desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
|
||||||
alt = desc.blank? ? nil : "(#{desc})"
|
alt = desc.blank? ? nil : "(#{desc})"
|
||||||
"!#{style}#{image_url}#{alt}!"
|
"!#{style}#{image_url}#{alt}!"
|
||||||
else
|
else
|
||||||
"!#{style}#{filename}!"
|
m
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,7 +89,9 @@ class ApplicationHelperTest < HelperTestCase
|
|||||||
def test_attached_images
|
def test_attached_images
|
||||||
to_test = {
|
to_test = {
|
||||||
'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
||||||
'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />'
|
'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
|
||||||
|
'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
|
||||||
|
'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />'
|
||||||
}
|
}
|
||||||
attachments = Attachment.find(:all)
|
attachments = Attachment.find(:all)
|
||||||
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user