##// END OF EJS Templates
Fixed: http links containing parentheses fail to reder correctly (#1591). Patch by Paul Rivier....
Jean-Philippe Lang -
r1869:14b4afeec90a
parent child
Show More
@@ -788,10 +788,10 class RedCloth3 < String
788 ":
788 ":
789 ([\w\/]\S+?) # $url
789 ([\w\/]\S+?) # $url
790 (\/)? # $slash
790 (\/)? # $slash
791 ([^\w\/;]*?) # $post
791 ([^\w\=\/;\(\)]*?) # $post
792 (?=<|\s|$)
792 (?=<|\s|$)
793 /x
793 /x
794
794 #"
795 def inline_textile_link( text )
795 def inline_textile_link( text )
796 text.gsub!( LINK_RE ) do |m|
796 text.gsub!( LINK_RE ) do |m|
797 pre,atts,text,title,url,slash,post = $~[1..7]
797 pre,atts,text,title,url,slash,post = $~[1..7]
@@ -799,6 +799,12 class RedCloth3 < String
799 url, url_title = check_refs( url )
799 url, url_title = check_refs( url )
800 title ||= url_title
800 title ||= url_title
801
801
802 # Idea below : an URL with unbalanced parethesis and
803 # ending by ')' is put into external parenthesis
804 if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
805 url=url[0..-2] # discard closing parenth from url
806 post = ")"+post # add closing parenth to post
807 end
802 atts = pba( atts )
808 atts = pba( atts )
803 atts = " href=\"#{ url }#{ slash }\"#{ atts }"
809 atts = " href=\"#{ url }#{ slash }\"#{ atts }"
804 atts << " title=\"#{ title }\"" if title
810 atts << " title=\"#{ title }\"" if title
@@ -144,7 +144,7 module Redmine
144 (\S+?) # url
144 (\S+?) # url
145 (\/)? # slash
145 (\/)? # slash
146 )
146 )
147 ([^\w\=\/;]*?) # post
147 ([^\w\=\/;\(\)]*?) # post
148 (?=<|\s|$)
148 (?=<|\s|$)
149 }x unless const_defined?(:AUTO_LINK_RE)
149 }x unless const_defined?(:AUTO_LINK_RE)
150
150
@@ -156,7 +156,13 module Redmine
156 # don't replace URL's that are already linked
156 # don't replace URL's that are already linked
157 # and URL's prefixed with ! !> !< != (textile images)
157 # and URL's prefixed with ! !> !< != (textile images)
158 all
158 all
159 else
159 else
160 # Idea below : an URL with unbalanced parethesis and
161 # ending by ')' is put into external parenthesis
162 if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
163 url=url[0..-2] # discard closing parenth from url
164 post = ")"+post # add closing parenth to post
165 end
160 %(#{leading}<a class="external" href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post})
166 %(#{leading}<a class="external" href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post})
161 end
167 end
162 end
168 end
@@ -38,10 +38,18 class ApplicationHelperTest < HelperTestCase
38 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
38 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
39 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
39 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
40 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
40 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
41 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
42 '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
43 '(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)',
44 '(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).',
45 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
46 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
47 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
41 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
48 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
42 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
49 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
43 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
50 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
44 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
51 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
52 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
45 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
53 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
46 }
54 }
47 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
55 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
General Comments 0
You need to be logged in to leave comments. Login now