Permalink
Browse files

Raise an Error on a unterminated heredoc

When processing verbatim blocks RDoc attempts to detect if they are ruby
code.  If the verbatim block contains an unterminated here-document a
NoMethodError would be raised.  This causes RDoc to crash.

Now an RDoc::RubyLex::Error is raised which allows the HTML processor to
create an un-highlighted <pre> element instead.

Reported by darix
  • Loading branch information...
1 parent 7cfb97a commit f4f5b94285aa9b20cacf78bda61450e17be63a22 @drbrain drbrain committed Feb 28, 2013
Showing with 16 additions and 0 deletions.
  1. +2 −0 History.rdoc
  2. +2 −0 lib/rdoc/ruby_lex.rb
  3. +12 −0 test/test_rdoc_ruby_lex.rb
View
@@ -5,6 +5,8 @@
Pointed out by Michael Granger
* Moved RubyGems documentation installed message into RDoc hook. For
RubyGems bug #469 by Jeff Sandberg
+ * An Error is now raised when a heredoc is not terminated. Fixes exceptions
+ when processing comment blocks. Reported by darix
=== 4.0.0 / 2013-02-24
View
@@ -1028,6 +1028,8 @@ def identify_here_document
end
if output_heredoc then
+ raise Error, "Missing terminating #{quoted} for string" unless l
+
doc << l.chomp
else
doc << '"'
View
@@ -162,6 +162,18 @@ def test_class_tokenize_heredoc_indent
assert_equal expected, tokens
end
+ def test_class_tokenize_heredoc_missing_end
+ e = assert_raises RDoc::RubyLex::Error do
+ RDoc::RubyLex.tokenize <<-'RUBY', nil
+>> string1 = <<-TXT
+>" That's swell
+>" TXT
+ RUBY
+ end
+
+ assert_equal 'Missing terminating TXT for string', e.message
+ end
+
def test_class_tokenize_heredoc_percent_N
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
a b <<-U

0 comments on commit f4f5b94

Please sign in to comment.