diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 01831461e3..9b5de62fd6 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -63,8 +63,8 @@ def cross_reference name, text = nil, code = true
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
- if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
- text ||= "#{CGI.unescape $'} at #{$1}
"
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
+ text ||= [CGI.unescape($'), (" at #{$1}
" if $~.begin(1))].join("")
code = false
else
text ||= name
@@ -139,35 +139,34 @@ def gen_url url, text
# Creates an HTML link to +name+ with the given +text+.
def link name, text, code = true
- if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
name = $1
label = $'
end
- ref = @cross_reference.resolve name, text
+ ref = @cross_reference.resolve name, text if name
case ref
when String then
ref
else
- path = ref.as_href @from_path
+ path = ref ? ref.as_href(@from_path) : +""
if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
text = "#{CGI.escapeHTML text}
"
end
- if path =~ /#/ then
- path << "-label-#{label}"
- elsif ref.sections and
- ref.sections.any? { |section| label == section.title } then
- path << "##{label}"
- else
- if ref.respond_to?(:aref)
+ if label
+ if path =~ /#/
+ path << "-label-#{label}"
+ elsif ref&.sections&.any? { |section| label == section.title }
+ path << "##{label}"
+ elsif ref.respond_to?(:aref)
path << "##{ref.aref}-label-#{label}"
else
path << "#label-#{label}"
end
- end if label
+ end
"#{text}"
end
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index 4b87dd5da5..dc4488195a 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -133,6 +133,18 @@ def test_convert_RDOCLINK_rdoc_ref_label
'rdoc-ref:C1@foo'
end
+ def test_convert_RDOCLINK_rdoc_ref_label_in_current_file
+ result = @to.convert 'rdoc-ref:@foo'
+
+ assert_equal para("foo"), result,
+ 'rdoc-ref:@foo'
+
+ result = @to.convert '{Foo}[rdoc-ref:@foo]'
+
+ assert_equal para("Foo"), result,
+ '{Foo}[rdoc-ref:@foo]'
+ end
+
def test_gen_url
assert_equal 'Some class',
@to.gen_url('rdoc-ref:C1', 'Some class')