Skip to content

Commit 17dd1fc

Browse files
committed
Fix Document-attr in the C parser
Previously the comment-open marker was not included in the comment returned from find_attr_comment. This meant that normalization would not strip the "*"s correctly leading to broken output. Now the opening "*"s are included, but only when the Document-attr is on the same line as the opening "/*" or on the line following the opening "/*". Fixes #271
1 parent 9d0281d commit 17dd1fc

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

History.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
yield and &block are present. Pull request #281 by Victor Bilyk.
66
* Fixed merging of rd-style and hash-style comments at the top of a file.
77
Bug #266 by Zachary Scott.
8+
* Fixed Document-attr in the C parser. Bug #271 by Hanmac.
89
* Removed duplicated condition in superclass fixup. Pull request #282 by
910
Benoit Daloze.
1011

lib/rdoc/parser/c.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,10 @@ def find_attr_comment var_name, attr_name, read = nil, write = nil
594594
\s*#{attr_name}\s*,
595595
#{rw},.*?\)\s*;%xm then
596596
$1
597-
elsif @content =~ %r%Document-attr:\s#{attr_name}\s*?\n
598-
((?>.*?\*/))%xm then
599-
$1
597+
elsif @content =~ %r%(/\*.*?(?:\s*\*\s*)?)
598+
Document-attr:\s#{attr_name}\s*?\n
599+
((?>(.|\n)*?\*/))%x then
600+
"#{$1}\n#{$2}"
600601
else
601602
''
602603
end

test/test_rdoc_parser_c.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,47 @@ def test_find_alias_comment
736736
assert_equal "/*\n * comment\n */\n\n", comment.text
737737
end
738738

739+
def test_find_attr_comment_document_attr
740+
parser= util_parser <<-C
741+
/*
742+
* Document-attr: y
743+
* comment
744+
*/
745+
C
746+
747+
comment = parser.find_attr_comment nil, 'y'
748+
749+
assert_equal "/*\n * \n * comment\n */", comment.text
750+
end
751+
752+
def test_find_attr_comment_document_attr_oneline
753+
parser= util_parser <<-C
754+
/* Document-attr: y
755+
* comment
756+
*/
757+
C
758+
759+
comment = parser.find_attr_comment nil, 'y'
760+
761+
assert_equal "/* \n * comment\n */", comment.text
762+
end
763+
764+
def test_find_attr_comment_document_attr_overlap
765+
parser= util_parser <<-C
766+
/* Document-attr: x
767+
* comment
768+
*/
769+
770+
/* Document-attr: y
771+
* comment
772+
*/
773+
C
774+
775+
comment = parser.find_attr_comment nil, 'y'
776+
777+
assert_equal "/* \n * comment\n */", comment.text
778+
end
779+
739780
def test_find_class_comment
740781
@options.rdoc_include << File.dirname(__FILE__)
741782

0 commit comments

Comments
 (0)