Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rails_autolink/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ def auto_link(text, *args, &block) #link = :all, html = {}, &block)

private

WORD_PATTERN = RUBY_VERSION < '1.9' ? '\w' : '\p{Word}'

AUTO_LINK_RE = %r{
(?: ((?:ed2k|ftp|http|https|irc|mailto|news|gopher|nntp|telnet|webcal|xmpp|callto|feed|svn|urn|aim|rsync|tag|ssh|sftp|rtsp|afs|file):)// | www\.\w )
(?: ((?:ed2k|ftp|http|https|irc|mailto|news|gopher|nntp|telnet|webcal|xmpp|callto|feed|svn|urn|aim|rsync|tag|ssh|sftp|rtsp|afs|file):)// | www\.#{WORD_PATTERN} )
[^\s<\u00A0"]+
}ix

Expand All @@ -83,8 +85,6 @@ def auto_link(text, *args, &block) #link = :all, html = {}, &block)

BRACKETS = { ']' => '[', ')' => '(', '}' => '{' }

WORD_PATTERN = RUBY_VERSION < '1.9' ? '\w' : '\p{Word}'

# Turns all urls into clickable links. If a block is given, each url
# is yielded and the result is used as the link text.
def auto_link_urls(text, html_options = {}, options = {})
Expand Down
14 changes: 14 additions & 0 deletions test/test_rails_autolink.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def test_auto_link_with_options_hash
:link => :all, :html => { :class => "menu", :target => "_blank" })
end

def test_auto_www_link_with_idn
domains = %w(
www.rammstein.tube
www.grå.org
www.सार्वभौमिक-स्वीकृति-परीक्षण.संगठन
)

domains.each do |domain|
assert_equal "Welcome to my new blog at <a href=\"http://#{domain}\">#{domain}</a>.",
auto_link("Welcome to my new blog at #{domain}.")
end
end

def test_auto_link_with_multiple_trailing_punctuations
url = "http://youtube.com"
url_result = generate_result(url)
Expand Down Expand Up @@ -320,6 +333,7 @@ def test_auto_link_parsing
http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
http://около.кола/колокола
https://123domain.com https://123.com https://123.domain.com https://www.123.domain.com
https://grå.org https://rammstein.tube https://https://सार्वभौमिक-स्वीकृति-परीक्षण.संगठन
)

urls.each do |url|
Expand Down