From 046d87ac45f1100d30795dcd65357f05d6819b39 Mon Sep 17 00:00:00 2001 From: harada Date: Tue, 8 Jan 2019 16:33:44 +0900 Subject: [PATCH 2/2] Interpret trailing hyphens as URL. --- lib/redmine/wiki_formatting.rb | 2 +- lib/redmine/wiki_formatting/textile/redcloth3.rb | 8 ++++---- test/helpers/application_helper_test.rb | 9 +++++++++ .../redmine/wiki_formatting/textile_formatter_test.rb | 6 ++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index 66764551d..d4dd05a93 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -125,7 +125,7 @@ module Redmine ([^<]\S*?) # url (\/)? # slash ) - ((?:>)?|[^[:alnum:]_\=\/;\(\)]*?) # post + ((?:>)?|[^[:alnum:]_\=\/;\(\)\-]*?) # post (?=<|\s|$) }x unless const_defined?(:AUTO_LINK_RE) diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb index 9107da611..35834927a 100644 --- a/lib/redmine/wiki_formatting/textile/redcloth3.rb +++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb @@ -271,9 +271,9 @@ class RedCloth3 < String @urlrefs = {} @shelf = [] - textile_rules = [:block_textile_table, :block_textile_lists, - :block_textile_prefix, :inline_textile_image, :inline_textile_link, - :inline_textile_code, :inline_textile_span, :glyphs_textile] + textile_rules = [:block_textile_table, :block_textile_lists, :block_textile_prefix, + :inline_textile_image, :inline_textile_code, :inline_textile_span, :inline_textile_link, + :glyphs_textile] markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule, :block_markdown_bq, :block_markdown_lists, :inline_markdown_reflink, :inline_markdown_link] @@ -828,7 +828,7 @@ class RedCloth3 < String [[:alnum:]_\/]\S+? ) (\/)? # $slash - ([^[:alnum:]_\=\/;\(\)]*?) # $post + ([^[:alnum:]_\=\/;\(\)\-]*?) # $post ) (?=<|\s|$) /x diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 5561e2f40..88c6da5e8 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -282,6 +282,15 @@ RAW to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } end + def test_textile_links_with_hyphens + to_test = { + '(see "inline link":http://www.foo.bar/Test-)' => '(see inline link)', + 'http://foo.bar/page?p=1&t=z&s=-' => 'http://foo.bar/page?p=1&t=z&s=-', + 'This is an intern "link":/foo/bar-' => 'This is an intern link', + } + to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } + end + def test_redmine_links user_with_email_login = User.generate!(:login => 'abcd@example.com') user_with_email_login_2 = User.generate!(:login => 'foo.bar@example.com') diff --git a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb index 97912cbdf..e55980fff 100644 --- a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb @@ -621,6 +621,12 @@ EXPECTED assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '') end + def test_should_link_url_with_hyphens + assert_html_output({ + 'http://www.redmine.org/example-' => 'http://www.redmine.org/example-' + }) + end + private def assert_html_output(to_test, expect_paragraph = true) -- 2.20.1