Skip to content

Commit 06bf78d

Browse files
committed
Fix RDoc::Markup::Parser for a header followed by a non-text token. Issue #56
1 parent 311d8c3 commit 06bf78d

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

History.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
=== 3.9.1 / ??
22

33
* Bug fixes
4+
* Fix RDoc::Markup parser for a header followed by a non-text token. Issue
5+
#56 by Adam Tait
46
* Fix bug report URL when rdoc crashes.
57

68
=== 3.9 / 2011-07-30

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def self.const_missing const_name # :nodoc:
104104
##
105105
# RDoc version you are using
106106

107-
VERSION = '3.9'
107+
VERSION = '3.9.1'
108108

109109
##
110110
# Method visibilities

lib/rdoc/markup/parser.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ def initialize
8686
# Builds a Heading of +level+
8787

8888
def build_heading level
89-
_, text, = get # TEXT
90-
heading = RDoc::Markup::Heading.new level, text
91-
skip :NEWLINE
92-
93-
heading
89+
type, text, = get
90+
91+
text = case type
92+
when :TEXT then
93+
skip :NEWLINE
94+
text
95+
else
96+
unget
97+
''
98+
end
99+
100+
RDoc::Markup::Heading.new level, text
94101
end
95102

96103
##

test/test_rdoc_markup_parser.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ def test_parse_heading_bullet
248248
assert_equal expected, @RMP.parse(str).parts
249249
end
250250

251+
def test_parse_heading_empty
252+
str = <<-STR
253+
===
254+
* bullet
255+
STR
256+
257+
expected = [
258+
@RM::Heading.new(3, ''),
259+
@RM::BlankLine.new,
260+
@RM::List.new(:BULLET, *[
261+
@RM::ListItem.new(nil,
262+
@RM::Paragraph.new('bullet'))]),
263+
]
264+
265+
assert_equal expected, @RMP.parse(str).parts
266+
end
267+
251268
def test_parse_heading_heading
252269
str = '= ='
253270

@@ -1085,6 +1102,23 @@ def test_tokenize_heading
10851102
assert_equal expected, @RMP.tokenize(str)
10861103
end
10871104

1105+
def test_tokenize_heading_empty
1106+
str = <<-STR
1107+
===
1108+
* bullet
1109+
STR
1110+
1111+
expected = [
1112+
[:HEADER, 3, 0, 0],
1113+
[:NEWLINE, "\n", 3, 0],
1114+
[:BULLET, "*", 0, 1],
1115+
[:TEXT, "bullet", 2, 1],
1116+
[:NEWLINE, "\n", 8, 1],
1117+
]
1118+
1119+
assert_equal expected, @RMP.tokenize(str)
1120+
end
1121+
10881122
def test_tokenize_heading_heading
10891123
str = <<-STR
10901124
= =

0 commit comments

Comments
 (0)