Skip to content

Commit ecae6cb

Browse files
committed
Disallow adding duplicate comments to a module
The C parser could add the same comment twice. This change works around this bug in the C parser.
1 parent 87e31ad commit ecae6cb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rdoc/class_module.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def add_comment comment, location
134134
else
135135
normalize_comment comment
136136
end
137+
138+
return if @comment_location.any? do |(c, l)|
139+
c == comment and l == location
140+
end
141+
137142
@comment_location << [comment, location]
138143

139144
self.comment = original

test/test_rdoc_class_module.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ def test_add_comment_comment
4141
assert_equal 'comment', cm.comment.text
4242
end
4343

44+
def test_add_comment_duplicate
45+
tl1 = @store.add_file 'one.rb'
46+
47+
cm = RDoc::ClassModule.new 'Klass'
48+
cm.add_comment '# comment 1', tl1
49+
cm.add_comment '# comment 1', tl1
50+
51+
assert_equal [['comment 1', tl1]], cm.comment_location
52+
end
53+
4454
def test_add_comment_stopdoc
4555
tl = @store.add_file 'file.rb'
4656

0 commit comments

Comments
 (0)