Skip to content

Commit 640c26c

Browse files
committed
Avoid linking file paths inside backticks
1 parent 475792c commit 640c26c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ def convert_tt_crossref(flow_items, index)
239239
return unless RDoc::Markup::AttrChanger === closer
240240
return unless tt_tag?(closer.turn_off, true)
241241

242+
# Skip file paths - they should remain as literal code, not be linked
243+
return if string.include?('/')
244+
242245
crossref_regexp = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
243246
match = crossref_regexp.match(string)
244247
return unless match

test/rdoc/markup/to_html_crossref_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,23 @@ def test_link_class_method_full
329329
@to.link('Parent::m', 'Parent::m')
330330
end
331331

332+
def test_convert_CROSSREF_file_path_not_linked
333+
# Must use hyperlink_all = false for file path pattern to match the right regex
334+
@options.hyperlink_all = false
335+
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
336+
337+
file = @store.add_file 'lib/foo/bar.rb'
338+
file.parser = RDoc::Parser::Ruby
339+
340+
# Verify the file IS resolvable via rdoc-ref (sanity check)
341+
result = @to.convert 'rdoc-ref:lib/foo/bar.rb'
342+
assert_equal para('<a href="lib/foo/bar_rb.html">lib/foo/bar.rb</a>'), result
343+
344+
# But file paths inside backticks should NOT be converted to links
345+
result = @to.convert '+lib/foo/bar.rb+'
346+
assert_equal para('<code>lib/foo/bar.rb</code>'), result
347+
end
348+
332349
def para(text)
333350
"\n<p>#{text}</p>\n"
334351
end

0 commit comments

Comments
 (0)