Skip to content

Commit

Permalink
Only word-ending colon separates new definition
Browse files Browse the repository at this point in the history
When followed by non-space characters, rather it looks like a URL or a
path name on Windows.
  • Loading branch information
nobu committed Dec 6, 2023
1 parent 1904e90 commit 72c6560
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@ def handle_constants(type, var_name, const_name, definition)
# "/* definition: comment */" form. The literal ':' and '\' characters
# can be escaped with a backslash.
if type.downcase == 'const' then
no_match, new_definition, new_comment = comment.text.split(/(\A.*):/)
if /\A(.+?)?:(?!\S)/ =~ comment.text
new_definition, new_comment = $1, $'

if no_match and no_match.empty? then
if new_definition.empty? then # Default to literal C definition
if !new_definition # Default to literal C definition
new_definition = definition
else
new_definition = new_definition.gsub(/\\([\\:])/, '\1')
Expand Down
6 changes: 6 additions & 0 deletions test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ def test_do_constants
/* TEST\:TEST: Checking to see if escaped colon works */
rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
/* TEST: TEST:Checking to see if only word-ending colon works */
rb_define_const(cFoo, "TEST2", rb_str_new2("TEST:TEST"));
/* \\: The file separator on MS Windows */
rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
Expand Down Expand Up @@ -538,6 +541,9 @@ def test_do_constants
assert_equal ['TEST', 'TEST:TEST',
'Checking to see if escaped colon works '],
constants.shift
assert_equal ['TEST2', 'TEST',
'TEST:Checking to see if only word-ending colon works '],
constants.shift
assert_equal ['MSEPARATOR', '\\',
'The file separator on MS Windows '],
constants.shift
Expand Down

0 comments on commit 72c6560

Please sign in to comment.