diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 6477f98910..5897fa0cbf 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -154,6 +154,13 @@ def initialize(pipe: false, output_decoration: true)
UNSAFE_URL_SCHEME_REGEXP = /\A(?:javascript|vbscript|data|file):/i
+ ##
+ # Splits the part of an rdoc-image link after "rdoc-image:" into the
+ # image URL and the alt text. A port number after the host is part of
+ # the URL.
+
+ IMAGE_URL_AND_ALT_REGEXP = %r{\A((?:[A-Za-z][A-Za-z0-9+.\-]*://[^/:?#]*(?::\d+(?=[/?#:]|\z))?)?[^:]*)(?::(.*))?\z}m
+
# :nodoc:
URL_CHARACTERS_REGEXP_STR = /[A-Za-z0-9\-._~:\/\?#\[\]@!$&'\(\)*+,;%=]/.source
@@ -203,7 +210,8 @@ def handle_RDOCLINK(url) # :nodoc:
# Split the string after "rdoc-image:" into url and alt.
# "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
# "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
- url, alt = $'.split(/:(?!\/)/, 2)
+ # "http://example.com:8080/image.jpg:alt text" => ["http://example.com:8080/image.jpg", "alt text"]
+ url, alt = $'.match(IMAGE_URL_AND_ALT_REGEXP).captures
if alt && !alt.empty?
%[]
else
diff --git a/test/rdoc/markup/to_html_test.rb b/test/rdoc/markup/to_html_test.rb
index 6d0107602c..c1c3e220f6 100644
--- a/test/rdoc/markup/to_html_test.rb
+++ b/test/rdoc/markup/to_html_test.rb
@@ -903,6 +903,22 @@ def test_convert_TIDYLINK_image_external
assert_equal expected, result
end
+ def test_convert_TIDYLINK_image_external_with_port
+ result =
+ @to.convert '{rdoc-image:http://example.com:8080/path/to/image.jpg:alt text}[http://example.com]'
+
+ expected =
+ "\n
