##// END OF EJS Templates
Fixed: Textile image with style attribute cause internal server error....
Jean-Philippe Lang -
r1004:5f871e965746
parent child
Show More
@@ -165,16 +165,16 module ApplicationHelper
165 # when using an image link, try to use an attachment, if possible
165 # when using an image link, try to use an attachment, if possible
166 attachments = options[:attachments]
166 attachments = options[:attachments]
167 if attachments
167 if attachments
168 text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
168 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
169 align = $1
169 style = $1
170 filename = $2
170 filename = $6
171 rf = Regexp.new(filename, Regexp::IGNORECASE)
171 rf = Regexp.new(filename, Regexp::IGNORECASE)
172 # search for the picture in attachments
172 # search for the picture in attachments
173 if found = attachments.detect { |att| att.filename =~ rf }
173 if found = attachments.detect { |att| att.filename =~ rf }
174 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
174 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
175 "!#{align}#{image_url}!"
175 "!#{style}#{image_url}!"
176 else
176 else
177 "!#{align}#{filename}!"
177 "!#{style}#{filename}!"
178 end
178 end
179 end
179 end
180 end
180 end
@@ -25,7 +25,8 module Redmine
25
25
26 class TextileFormatter < RedCloth
26 class TextileFormatter < RedCloth
27
27
28 RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros]
28 # auto_link rule after textile rules so that it doesn't break !image_url! tags
29 RULES = [:textile, :inline_auto_link, :inline_auto_mailto, :inline_toc, :inline_macros]
29
30
30 def initialize(*args)
31 def initialize(*args)
31 super
32 super
@@ -44,12 +44,18 class ApplicationHelperTest < HelperTestCase
44 textilizable('test@foo.bar')
44 textilizable('test@foo.bar')
45 end
45 end
46
46
47 def test_textile_tags
47 def test_inline_images
48 to_test = {
48 to_test = {
49 # inline images
50 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
49 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
51 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
50 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
52 # textile links
51 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
52 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />',
53 }
54 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
55 end
56
57 def test_textile_external_links
58 to_test = {
53 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
59 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
54 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
60 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
55 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>'
61 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>'
General Comments 0
You need to be logged in to leave comments. Login now