diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-04-30 00:54:47 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-04-29 16:55:37 +0000 |
commit | c2871161b453b37b444a759ebec6260c2c0fd0a4 (patch) | |
tree | 7da29d8cd111756c72e2be709b61a882ec549456 /lib/rdoc | |
parent | 85a9fd1902e2eba7910aa7490a8f09560dff451f (diff) |
[ruby/rdoc] Fix polynominal backtracking
Fix https://github.com/ruby/rdoc/pull/995
https://github.com/ruby/rdoc/commit/1311ca8c50
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/comment.rb | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index 9e90999eac..63197492c4 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -97,42 +97,26 @@ class RDoc::Comment # comment. The difficulty is to make sure not to match lines starting # with ARGF at the same indent, but that are after the first description # paragraph. - if @text =~ /^\s*:?call-seq:(.*?(?:\S).*?)^\s*$/m then + if /^(?<S> ((?!\n)\s)*+ (?# whitespaces except newline)) + :?call-seq: + (?<B> \g<S>(?<N>\n|\z) (?# trailing spaces))? + (?<seq> + (\g<S>(?!\w)\S.*\g<N>)* + (?> + (?<H> \g<S>\w+ (?# ' # ARGF' in the example above)) + .*\g<N>)? + (\g<S>\S.*\g<N> (?# other non-blank line))*+ + (\g<B>+(\k<H>.*\g<N> (?# ARGF.to_a lines))++)*+ + ) + (?m:^\s*$|\z) + /x =~ @text + seq = $~[:seq] + all_start, all_stop = $~.offset(0) - seq_start, seq_stop = $~.offset(1) - - # we get the following lines that start with the leading word at the - # same indent, even if they have blank lines before - if $1 =~ /(^\s*\n)+^(\s*\w+)/m then - leading = $2 # ' * ARGF' in the example above - re = %r% - \A( - (^\s*\n)+ - (^#{Regexp.escape leading}.*?\n)+ - )+ - ^\s*$ - %xm - - if @text[seq_stop..-1] =~ re then - all_stop = seq_stop + $~.offset(0).last - seq_stop = seq_stop + $~.offset(1).last - end - end - - seq = @text[seq_start..seq_stop] - seq.gsub!(/^\s*(\S|\n)/m, '\1') @text.slice! all_start...all_stop - method.call_seq = seq.chomp - - else - regexp = /^\s*:?call-seq:(.*?)(^\s*$|\z)/m - if regexp =~ @text then - @text = @text.sub(regexp, '') - seq = $1 - seq.gsub!(/^\s*/, '') - method.call_seq = seq - end + seq.gsub!(/^\s*/, '') + method.call_seq = seq end method |