From 35a14cbfdc9fb65e046d22af02dbf95398284b5d 2008-03-21 17:39:02 From: Jean-Philippe Lang Date: 2008-03-21 17:39:02 Subject: [PATCH] Wiki links: * fixes wiki links with pipe in table (closes #893, #870, #894) * prevent wiki link matching on multiple lines git-svn-id: http://redmine.rubyforge.org/svn/trunk@1280 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f3b16bb..510ecd1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -239,7 +239,7 @@ module ApplicationHelper # [[project:|mytext]] # [[project:mypage]] # [[project:mypage|mytext]] - text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m| + text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m| link_project = project esc, all, page, title = $1, $2, $3, $5 if esc.nil? diff --git a/lib/redcloth.rb b/lib/redcloth.rb index 14940cb..9452c26 100644 --- a/lib/redcloth.rb +++ b/lib/redcloth.rb @@ -510,7 +510,8 @@ class RedCloth < String ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m cells = [] - row.split( '|' ).each do |cell| + #row.split( /\(?!\[\[[^\]])|(?![^\[]\]\])/ ).each do |cell| + row.split( /\|(?![^\[\|]*\]\])/ ).each do |cell| ctyp = 'd' ctyp = 'h' if cell =~ /^_/ diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 2b90b8f..66499c0 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -142,7 +142,21 @@ class ApplicationHelperTest < HelperTestCase "
content
" => "
<div>content</div>
", } to_test.each { |text, result| assert_equal result, textilizable(text) } - + end + + def test_wiki_links_in_tables + to_test = {"|Cell 11|Cell 12|Cell 13|\n|Cell 21|Cell 22||\n|Cell 31||Cell 33|" => + 'Cell 11Cell 12Cell 13' + + 'Cell 21Cell 22' + + 'Cell 31Cell 33', + + "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => + 'Link title' + + 'Other title' + + 'Cell 21Last page' + } + @project = Project.find(1) + to_test.each { |text, result| assert_equal "#{result}
", textilizable(text).gsub(/[\t\n]/, '') } end def test_macro_hello_world