Skip to content

Commit 1ccd1d5

Browse files
committed
Bypass ERB's Ruby syntax error
The legacy lexical analyzer and parser of RDoc 5 process ERB file with no errors because of complex bug. RDoc 6 what uses Ripper causes errors when processes ERB file. It was just bug fix but RDoc lost compatibility. For example, when installs ActiveRecord 5.1.4 by "gem install activerecord -v 5.1.4", it uses RDoc internal, so the RDoc crashes if it's RDoc 6.0.0. This commit provides compatibility behavior with RDoc 5 or older. When an exception occurs inside Ruby parser, confirms that the source code contains "<%" and "%>" to detect ERB file. Skips it if RDoc guesses that the file is ERB by the logic.
1 parent b477af8 commit 1ccd1d5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def initialize(top_level, file_name, content, options, stats)
178178
@size = 0
179179
@token_listeners = nil
180180
@scanner = RDoc::RipperStateLex.parse(content)
181+
@content = content
181182
@scanner_point = 0
182183
@prev_seek = nil
183184
@markup = @options.markup
@@ -2067,6 +2068,12 @@ def scan
20672068
parse_top_level_statements @top_level
20682069

20692070
rescue StandardError => e
2071+
if @content.include?('<%') and @content.include?('%>') then
2072+
# Maybe, this is ERB.
2073+
$stderr.puts "\033[2KRDoc detects ERB file. Skips it for compatibility:"
2074+
$stderr.puts @file_name
2075+
return
2076+
end
20702077
bytes = ''
20712078

20722079
if @scanner_point >= @scanner.size

0 commit comments

Comments
 (0)