diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index c05a3b5b17..259bc85c11 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -156,7 +156,7 @@ def link(name, text, code = true, rdoc_ref: false)
ref = @cross_reference.resolve name, text if name
case ref
- when String then
+ when String
if rdoc_ref && @options.warn_missing_rdoc_ref
puts "#{@from_path}: `rdoc-ref:#{name}` can't be resolved for `#{text}`"
end
@@ -164,8 +164,18 @@ def link(name, text, code = true, rdoc_ref: false)
else
path = ref ? ref.as_href(@from_path) : +""
- if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
- text = "#{CGI.escapeHTML text}"
+ text = if code && RDoc::TopLevel === ref
+ # Allow explicit rdoc-ref links to files, but don't wrap in code tags
+ if rdoc_ref
+ text
+ else
+ # Don't auto-link file paths in backticks
+ return "#{CGI.escapeHTML text}"
+ end
+ elsif code && RDoc::CodeObject === ref
+ "#{CGI.escapeHTML text}"
+ else
+ text
end
if label
diff --git a/test/rdoc/markup/to_html_crossref_test.rb b/test/rdoc/markup/to_html_crossref_test.rb
index 3f5377cdba..8bba239ebc 100644
--- a/test/rdoc/markup/to_html_crossref_test.rb
+++ b/test/rdoc/markup/to_html_crossref_test.rb
@@ -329,6 +329,23 @@ def test_link_class_method_full
@to.link('Parent::m', 'Parent::m')
end
+ def test_convert_CROSSREF_file_path_not_linked
+ # Must use hyperlink_all = false for file path pattern to match the right regex
+ @options.hyperlink_all = false
+ @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
+
+ file = @store.add_file 'lib/foo/bar.rb'
+ file.parser = RDoc::Parser::Ruby
+
+ # Verify the file IS resolvable via rdoc-ref (sanity check)
+ result = @to.convert 'rdoc-ref:lib/foo/bar.rb'
+ assert_equal para('lib/foo/bar.rb'), result
+
+ # But file paths inside backticks should NOT be converted to links
+ result = @to.convert '+lib/foo/bar.rb+'
+ assert_equal para('lib/foo/bar.rb'), result
+ end
+
def para(text)
"\n
#{text}
\n" end