Fixed: Links get chopped by punctuation marks in anchors.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@775 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
cae547a7ea
commit
b4d66593ef
|
@ -1,6 +1,6 @@
|
||||||
require 'redcloth'
|
require 'redcloth'
|
||||||
require 'coderay'
|
require 'coderay'
|
||||||
|
require 'pp'
|
||||||
module Redmine
|
module Redmine
|
||||||
module WikiFormatting
|
module WikiFormatting
|
||||||
|
|
||||||
|
@ -81,27 +81,23 @@ module Redmine
|
||||||
(?:www\.) # www.*
|
(?:www\.) # www.*
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
[-\w]+ # subdomain or domain
|
(\S+?) # url
|
||||||
(?:\.[-\w]+)* # remaining subdomains or domain
|
(\/)? # slash
|
||||||
(?::\d+)? # port
|
|
||||||
(?:/(?:(?:[~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path
|
|
||||||
(?:\?[\w\+%&=.;-]+)? # query string
|
|
||||||
(?:\#[\w\-]*)? # trailing anchor
|
|
||||||
)
|
)
|
||||||
([[:punct:]]|\s|<|$) # trailing text
|
([^\w\=\/;]*?) # post
|
||||||
|
(?=<|\s|$)
|
||||||
}x unless const_defined?(:AUTO_LINK_RE)
|
}x unless const_defined?(:AUTO_LINK_RE)
|
||||||
|
|
||||||
# Turns all urls into clickable links (code from Rails).
|
# Turns all urls into clickable links (code from Rails).
|
||||||
def inline_auto_link(text)
|
def inline_auto_link(text)
|
||||||
text.gsub!(AUTO_LINK_RE) do
|
text.gsub!(AUTO_LINK_RE) do
|
||||||
all, a, b, c, d = $&, $1, $2, $3, $4
|
all, leading, proto, url, post = $&, $1, $2, $3, $6
|
||||||
if a =~ /<a\s/i || a =~ /![<>=]?/
|
if leading =~ /<a\s/i || leading =~ /![<>=]?/
|
||||||
# don't replace URL's that are already linked
|
# don't replace URL's that are already linked
|
||||||
# and URL's prefixed with ! !> !< != (textile images)
|
# and URL's prefixed with ! !> !< != (textile images)
|
||||||
all
|
all
|
||||||
else
|
else
|
||||||
text = b + c
|
%(#{leading}<a href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post})
|
||||||
%(#{a}<a href="#{b=="www."?"http://www.":b}#{c}">#{text}</a>#{d})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,8 @@ class ApplicationHelperTest < HelperTestCase
|
||||||
def test_auto_links
|
def test_auto_links
|
||||||
to_test = {
|
to_test = {
|
||||||
'http://foo.bar' => '<a href="http://foo.bar">http://foo.bar</a>',
|
'http://foo.bar' => '<a href="http://foo.bar">http://foo.bar</a>',
|
||||||
|
'http://foo.bar.' => '<a href="http://foo.bar">http://foo.bar</a>.',
|
||||||
|
'http://foo.bar/foo.bar#foo.bar.' => '<a href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
|
||||||
'www.foo.bar' => '<a href="http://www.foo.bar">www.foo.bar</a>',
|
'www.foo.bar' => '<a href="http://www.foo.bar">www.foo.bar</a>',
|
||||||
'http://foo.bar/page?p=1&t=z&s=' => '<a href="http://foo.bar/page?p=1&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>',
|
'http://foo.bar/page?p=1&t=z&s=' => '<a href="http://foo.bar/page?p=1&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>',
|
||||||
'http://foo.bar/page#125' => '<a href="http://foo.bar/page#125">http://foo.bar/page#125</a>'
|
'http://foo.bar/page#125' => '<a href="http://foo.bar/page#125">http://foo.bar/page#125</a>'
|
||||||
|
|
Loading…
Reference in New Issue