]> source.dussan.org Git - redmine.git/commitdiff
Merged r17906 from trunk to 4.0-stable (#30256).
authorGo MAEDA <maeda@farend.jp>
Sun, 3 Mar 2019 01:46:24 +0000 (01:46 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 3 Mar 2019 01:46:24 +0000 (01:46 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@17912 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/helpers/application_helper_test.rb

index e250c20ee0cd4c62c368029c16e8dfd033365542..8fa56ac55bfc21783aa49a9291cc52af8592426d 100644 (file)
@@ -787,7 +787,7 @@ module ApplicationHelper
   #   [[project:mypage]]
   #   [[project:mypage|mytext]]
   def parse_wiki_links(text, project, obj, attr, only_path, options)
-    text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
+    text.gsub!(/(!)?(\[\[([^\n\|]+?)(\|([^\n\|]+?))?\]\])/) do |m|
       link_project = project
       esc, all, page, title = $1, $2, $3, $5
       if esc.nil?
index 48304af254d93de07be20c08d1aa9039ee5fa7d8..26ca772b719e64d1b97a9a61e87867fe016e8641 100644 (file)
@@ -842,6 +842,47 @@ RAW
     end
   end
 
+  def test_wiki_links_with_square_brackets_in_project_name
+    User.current = User.find_by_login('jsmith')
+
+    another_project = Project.find(1) # eCookbook
+    another_project.name = "[foo]#{another_project.name}"
+    another_project.save
+
+    page = another_project.wiki.find_page('Another page')
+    page.title = "[bar]#{page.title}"
+    page.save
+
+    to_test = {
+      '[[[foo]eCookbook:]]' =>
+          link_to("[foo]eCookbook",
+                  "/projects/ecookbook/wiki",
+                  :class => "wiki-page"),
+      '[[[foo]eCookbook:CookBook documentation]]' =>
+          link_to("CookBook documentation",
+                  "/projects/ecookbook/wiki/CookBook_documentation",
+                  :class => "wiki-page"),
+      '[[[foo]eCookbook:[bar]Another page]]' =>
+          link_to("[bar]Another page",
+                  "/projects/ecookbook/wiki/%5Bbar%5DAnother_page",
+                  :class => "wiki-page"),
+      '[[[foo]eCookbook:Unknown page]]' =>
+          link_to("Unknown page",
+                  "/projects/ecookbook/wiki/Unknown_page",
+                  :class => "wiki-page new"),
+      '[[[foo]eCookbook:[baz]Unknown page]]' =>
+          link_to("[baz]Unknown page",
+                  "/projects/ecookbook/wiki/%5Bbaz%5DUnknown_page",
+                  :class => "wiki-page new"),
+    }
+    @project = Project.find(2)  # OnlineStore
+    with_settings :text_formatting => 'textile' do
+      to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
+    end
+    with_settings :text_formatting => 'markdown' do
+      to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text).strip }
+    end
+  end
 
   def test_wiki_links_within_local_file_generation_context
     to_test = {
@@ -1788,6 +1829,10 @@ RAW
           link_to("broken > more",
                   "/projects/ecookbook/wiki/Broken_%3E_more",
                   :class => "wiki-page new"),
+      '[[[foo]Including [square brackets] in wiki title]]' =>
+          link_to("[foo]Including [square brackets] in wiki title",
+                  "/projects/ecookbook/wiki/%5Bfoo%5DIncluding_%5Bsquare_brackets%5D_in_wiki_title",
+                  :class => "wiki-page new"),
     }
   end