From b4d66593ef6ed7b0d260cece6ffc41874b077cea Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 30 Sep 2007 15:16:58 +0000 Subject: [PATCH] Fixed: Links get chopped by punctuation marks in anchors. git-svn-id: http://redmine.rubyforge.org/svn/trunk@775 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/wiki_formatting.rb | 24 ++++++++------------ test/unit/helpers/application_helper_test.rb | 2 ++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index 623f2491fe..dc296547d1 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -1,6 +1,6 @@ require 'redcloth' require 'coderay' - +require 'pp' module Redmine module WikiFormatting @@ -79,29 +79,25 @@ module Redmine ( (?:https?://)| # protocol spec, or (?:www\.) # www.* - ) + ) ( - [-\w]+ # subdomain or domain - (?:\.[-\w]+)* # remaining subdomains or domain - (?::\d+)? # port - (?:/(?:(?:[~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path - (?:\?[\w\+%&=.;-]+)? # query string - (?:\#[\w\-]*)? # trailing anchor + (\S+?) # url + (\/)? # slash ) - ([[:punct:]]|\s|<|$) # trailing text + ([^\w\=\/;]*?) # post + (?=<|\s|$) }x unless const_defined?(:AUTO_LINK_RE) # Turns all urls into clickable links (code from Rails). def inline_auto_link(text) text.gsub!(AUTO_LINK_RE) do - all, a, b, c, d = $&, $1, $2, $3, $4 - if a =~ /=]?/ + all, leading, proto, url, post = $&, $1, $2, $3, $6 + if leading =~ /=]?/ # don't replace URL's that are already linked # and URL's prefixed with ! !> !< != (textile images) all - else - text = b + c - %(#{a}#{text}#{d}) + else + %(#{leading}#{proto + url}#{post}) end end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 10372fb743..24935bbb75 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -29,6 +29,8 @@ class ApplicationHelperTest < HelperTestCase def test_auto_links to_test = { 'http://foo.bar' => 'http://foo.bar', + 'http://foo.bar.' => 'http://foo.bar.', + 'http://foo.bar/foo.bar#foo.bar.' => 'http://foo.bar/foo.bar#foo.bar.', 'www.foo.bar' => 'www.foo.bar', 'http://foo.bar/page?p=1&t=z&s=' => 'http://foo.bar/page?p=1&t=z&s=', 'http://foo.bar/page#125' => 'http://foo.bar/page#125'