Skip to content

Commit

Permalink
Merge pull request #878 from ruby/pz-invalid-url
Browse files Browse the repository at this point in the history
Only parse valid URLs
  • Loading branch information
peterzhu2118 authored Apr 13, 2022
2 parents 32aca21 + 2bd8fcd commit bf519a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ def initialize options, markup = nil
#
# These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.

URL_CHARACTERS_REGEXP_STR = /[A-Za-z0-9\-._~:\/\?#\[\]@!$&'\(\)*+,;%=]/.source

##
# Adds regexp handlings.

def init_regexp_handlings
# external links
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)#{URL_CHARACTERS_REGEXP_STR}+\w/,
:HYPERLINK)
init_link_notation_regexp_handlings
end
Expand Down
1 change: 1 addition & 0 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ def test_convert_TIDYLINK_irc
def test_convert_with_exclude_tag
assert_equal "\n<p><code>aaa</code>[:symbol]</p>\n", @to.convert('+aaa+[:symbol]')
assert_equal "\n<p><code>aaa[:symbol]</code></p>\n", @to.convert('+aaa[:symbol]+')
assert_equal "\n<p><code>https:</code>-foobar</p>\n", @to.convert('<tt>https:</tt>-foobar')
assert_equal "\n<p><a href=\":symbol\">aaa</a></p>\n", @to.convert('aaa[:symbol]')
end

Expand Down

0 comments on commit bf519a6

Please sign in to comment.