diff --git a/lib/redcloth3.rb b/lib/redcloth3.rb index b2e44359..a5e63262 100644 --- a/lib/redcloth3.rb +++ b/lib/redcloth3.rb @@ -788,10 +788,10 @@ class RedCloth3 < String ": ([\w\/]\S+?) # $url (\/)? # $slash - ([^\w\/;]*?) # $post + ([^\w\=\/;\(\)]*?) # $post (?=<|\s|$) /x - +#" def inline_textile_link( text ) text.gsub!( LINK_RE ) do |m| pre,atts,text,title,url,slash,post = $~[1..7] @@ -799,6 +799,12 @@ class RedCloth3 < String url, url_title = check_refs( url ) title ||= url_title + # Idea below : an URL with unbalanced parethesis and + # ending by ')' is put into external parenthesis + if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) ) + url=url[0..-2] # discard closing parenth from url + post = ")"+post # add closing parenth to post + end atts = pba( atts ) atts = " href=\"#{ url }#{ slash }\"#{ atts }" atts << " title=\"#{ title }\"" if title diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index 649edfef..7dffff49 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -144,7 +144,7 @@ module Redmine (\S+?) # url (\/)? # slash ) - ([^\w\=\/;]*?) # post + ([^\w\=\/;\(\)]*?) # post (?=<|\s|$) }x unless const_defined?(:AUTO_LINK_RE) @@ -156,7 +156,13 @@ module Redmine # don't replace URL's that are already linked # and URL's prefixed with ! !> !< != (textile images) all - else + else + # Idea below : an URL with unbalanced parethesis and + # ending by ')' is put into external parenthesis + if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) ) + url=url[0..-2] # discard closing parenth from url + post = ")"+post # add closing parenth to post + end %(#{leading}#{proto + url}#{post}) end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 6db029ad..7ef47f59 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -38,10 +38,18 @@ class ApplicationHelperTest < HelperTestCase 'This is a link: http://foo.bar.' => 'This is a link: http://foo.bar.', 'A link (eg. http://foo.bar).' => 'A link (eg. http://foo.bar).', 'http://foo.bar/foo.bar#foo.bar.' => 'http://foo.bar/foo.bar#foo.bar.', + 'http://www.foo.bar/Test_(foobar)' => 'http://www.foo.bar/Test_(foobar)', + '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : http://www.foo.bar/Test_(foobar))', + '(see inline link : http://www.foo.bar/Test)' => '(see inline link : http://www.foo.bar/Test)', + '(see inline link : http://www.foo.bar/Test).' => '(see inline link : http://www.foo.bar/Test).', + '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see inline link)', + '(see "inline link":http://www.foo.bar/Test)' => '(see inline link)', + '(see "inline link":http://www.foo.bar/Test).' => '(see inline link).', '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', 'http://foo@www.bar.com' => 'http://foo@www.bar.com', + 'http://foo:bar@www.bar.com' => 'http://foo:bar@www.bar.com', 'ftp://foo.bar' => 'ftp://foo.bar', } to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) }