Skip to content

Commit

Permalink
Fixing auto link with www
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasba committed Oct 17, 2013
1 parent 9cda3c7 commit ef8e782
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/bb-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ module BBRuby
"Maybe try looking on [url]http://google.com[/url]",
:link],
'Link (Automatic)' => [
/(\A|\s)((https?:\/\/|www\.)[^\s<]+)/,
/(\A|\s)(https?:\/\/[^\s<]+)/,
' <a href="\2">\2</a>',
'Hyperlink (automatic)',
'Maybe try looking on http://www.google.com',
:link],
'Link (Automatic without leading http(s))' => [
/(\A|\s)(www\.[^\s<]+)/,
' <a href="http://\2">\2</a>',
'Hyperlink (automatic without leading http(s))',
'Maybe try looking on www.google.com',
:link],
'Image (Resized)' => [
/\[img(:.+)? size=#{@@quote_matcher}(\d+)x(\d+)\2\](.*?)\[\/img\1?\]/im,
'<img src="\5" style="width: \3px; height: \4px;" />',
Expand Down
7 changes: 6 additions & 1 deletion test/bb-ruby_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ def test_auto_link
assert_equal %Q(Try using google <a href="http://google.com">http://google.com</a>), 'Try using google http://google.com'.bbcode_to_html
assert_equal %Q(Try using googlehttp://google.com), 'Try using googlehttp://google.com'.bbcode_to_html
assert_equal %Q( <a href="http://google.com">http://google.com</a>), 'http://google.com'.bbcode_to_html
# links without leading http(s)
assert_equal %Q(previous text <a href="http://www.google.com">www.google.com</a> post text), 'previous text www.google.com post text'.bbcode_to_html
assert_equal %Q(Try using google <a href="http://www.google.com">www.google.com</a>), 'Try using google www.google.com'.bbcode_to_html
assert_equal %Q(Try using googlewww.google.com), 'Try using googlewww.google.com'.bbcode_to_html
assert_equal %Q( <a href="http://www.google.com">www.google.com</a>), 'www.google.com'.bbcode_to_html
end

def test_html_escaping
Expand Down Expand Up @@ -212,7 +217,7 @@ def test_to_html_with_formatting
end

def test_self_tag_list
assert_equal 33, BBRuby.tag_list.size
assert_equal 34, BBRuby.tag_list.size
end

def test_redefinition_of_tag_html
Expand Down

0 comments on commit ef8e782

Please sign in to comment.