]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Textile image with style attribute cause internal server error.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 19 Dec 2007 21:06:06 +0000 (21:06 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 19 Dec 2007 21:06:06 +0000 (21:06 +0000)
Also added tests for inline images with attributes and moved auto_link and auto_mailto rules after textile rules.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1017 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
lib/redmine/wiki_formatting.rb
test/unit/helpers/application_helper_test.rb

index 8deed9000ca8636bee5d9cc3e766745c3e573f51..a3509b99abee7c6ed919d7f25d4f99ea63c69170 100644 (file)
@@ -165,16 +165,16 @@ module ApplicationHelper
     # when using an image link, try to use an attachment, if possible
     attachments = options[:attachments]
     if attachments
-      text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
-        align = $1
-        filename = $2
+      text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
+        style = $1
+        filename = $6
         rf = Regexp.new(filename,  Regexp::IGNORECASE)
         # search for the picture in attachments
         if found = attachments.detect { |att| att.filename =~ rf }
           image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
-          "!#{align}#{image_url}!"
+          "!#{style}#{image_url}!"
         else
-          "!#{align}#{filename}!"
+          "!#{style}#{filename}!"
         end
       end
     end
index 4aebe9a967e514de5d2a281bdf5f3ef8c74ec75f..f7fa803a6b415b3951db3f53d4cf4182ff6930be 100644 (file)
@@ -25,7 +25,8 @@ module Redmine
   
     class TextileFormatter < RedCloth
       
-      RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros]
+      # auto_link rule after textile rules so that it doesn't break !image_url! tags
+      RULES = [:textile, :inline_auto_link, :inline_auto_mailto, :inline_toc, :inline_macros]
       
       def initialize(*args)
         super
index 06446d15e3891cc15a3e3118f657264841120a84..2af6c55994ff86b5529e7d743b73e0246bc22d5c 100644 (file)
@@ -44,12 +44,18 @@ class ApplicationHelperTest < HelperTestCase
       textilizable('test@foo.bar')
   end
   
-  def test_textile_tags
+  def test_inline_images
     to_test = {
-      # inline images
       '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
       'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
-      # textile links
+      'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
+      'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />',
+    }
+    to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
+  end
+  
+  def test_textile_external_links
+    to_test = {
       'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
       'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
       '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>'