Skip to content

Commit 4c69d57

Browse files
Fix a bug in which RDoc would not generate correct cross-reference links for
a class contained within a module of the same name (RDoc::RDoc, for instance).
1 parent a0a4276 commit 4c69d57

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

History.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ documentation about ri.
3333
* Provided an ri command-line option to control its caching behavior.
3434
* Improved RDoc's documentation. Added RI.txt to document ri.
3535

36-
* 24 Bug fixes:
36+
* 25 Bug fixes:
3737
* Fixed prototype detection in C parser. Can process ruby 1.8 C files
3838
again.
3939
* Fixed the main page for frameless template. Patch by Marcin Raczkowski.
@@ -45,6 +45,8 @@ documentation about ri.
4545
* Fixed a case where RDoc first would encounter Foo::Bar and then would
4646
encounter class Foo. Previously, RDoc erroneously would have considered
4747
that both a Foo class and a Foo module existed.
48+
* Fix a clase where RDoc would not generate correct cross-reference links
49+
to a class contained within a module of the same name (i.e. RDoc::RDoc)
4850
* Prevented RDoc from trying to parse binary files, which would produce
4951
garbage output.
5052
* RDoc now correctly converts ' characters to apostrophes, opening single

lib/rdoc/code_objects.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,12 @@ def initialize_classes_and_modules
406406

407407
# Find a named module
408408
def find_module_named(name)
409-
return self if self.name == name
409+
# First check the enclosed modules, then check the module itself,
410+
# then check the enclosing modules (this mirrors the check done by
411+
# the Ruby parser)
410412
res = @modules[name] || @classes[name]
411413
return res if res
414+
return self if self.name == name
412415
find_enclosing_module_named(name)
413416
end
414417

@@ -467,6 +470,7 @@ def find_symbol(symbol, method = nil)
467470
unless modules.empty? then
468471
module_name = modules.shift
469472
result = find_module_named(module_name)
473+
470474
if result then
471475
modules.each do |name|
472476
result = result.find_module_named(name)

test/rdoc_markup_to_html_crossref_reference.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ class Helper1
2424
class Helper2
2525
end
2626
end
27+
28+
class Ref_Class4
29+
class Ref_Class4
30+
end
31+
end

test/test_rdoc_markup_to_html_crossref.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def verify_invariant_crossrefs(xref)
199199

200200
# A link always should be generated for a file name.
201201
verify_file_crossref xref, @source_file_name, @source_file_name
202+
203+
# References should be generated correctly for a class scoped within
204+
# a class of the same name.
205+
verify_class_crossref xref, "Ref_Class4::Ref_Class4", "Ref_Class4::Ref_Class4"
202206
end
203207

204208
def test_handle_special_CROSSREF_no_underscore
@@ -224,6 +228,7 @@ def test_handle_special_CROSSREF_no_underscore
224228
verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
225229
verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
226230
verify_no_crossref xref, "Helper1"
231+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
227232

228233
klass = class_hash["Ref_Class2"]
229234
xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
@@ -232,6 +237,7 @@ def test_handle_special_CROSSREF_no_underscore
232237
verify_method_crossref xref, "Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
233238
verify_no_crossref xref, "#method"
234239
verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
240+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
235241

236242
# This one possibly is an rdoc bug...
237243
# Ref_Class2 has a nested Ref_Class3, but
@@ -251,6 +257,7 @@ def test_handle_special_CROSSREF_no_underscore
251257
verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
252258
verify_no_crossref xref, "Ref_Class3::Helper2"
253259
verify_class_crossref xref, "Helper1", "Ref_Class2::Ref_Class3::Helper1"
260+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
254261

255262
klass = class_hash["Ref_Class3"]
256263
xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
@@ -261,5 +268,20 @@ def test_handle_special_CROSSREF_no_underscore
261268
verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
262269
verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
263270
verify_class_crossref xref, "Helper1", "Ref_Class3::Helper1"
271+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
272+
273+
klass = class_hash["Ref_Class4"]
274+
xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
275+
verify_invariant_crossrefs xref
276+
# A Ref_Class4 reference inside a Ref_Class4 class containing a
277+
# Ref_Class4 class should resolve to the contained class.
278+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
279+
280+
klass = class_hash["Ref_Class4::Ref_Class4"]
281+
xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
282+
verify_invariant_crossrefs xref
283+
# A Ref_Class4 reference inside a Ref_Class4 class contained within
284+
# a Ref_Class4 class should resolve to the inner Ref_Class4 class.
285+
verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
264286
end
265287
end

0 commit comments

Comments
 (0)