This commit is contained in:
albert
2013-03-02 18:18:51 -05:00
parent 1136dc6dfa
commit e28c786fa1
2 changed files with 2 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ class DText
end
def self.parse_links(str)
str.gsub(/("[^"]+":(https?:\/\/|\/)\S+|https?:\/\/\S+)/m) do |url|
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+)+/) do |url|
if url =~ /^"([^"]+)":(.+)$/
text = $1
url = $2

View File

@@ -43,6 +43,7 @@ class DTextTest < ActiveSupport::TestCase
def test_urls
assert_equal('<p>a <a href="http://test.com">http://test.com</a> b</p>', p('a http://test.com b'))
assert_equal('<p><a href="http://test.com">http://test.com</a><br>b</p>', p("http://test.com\nb"))
assert_equal('<p>a <a href="http://test.com/~bob/image.jpg">http://test.com/~bob/image.jpg</a> b</p>', p('a http://test.com/~bob/image.jpg b'))
assert_equal('<p>a <a href="http://test.com/home.html#toc">http://test.com/home.html#toc</a> b</p>', p('a http://test.com/home.html#toc b'))
assert_equal('<p>a <a href="http://test.com">http://test.com</a>. b</p>', p('a http://test.com. b'))