Skip to content

Commit f7bb997

Browse files
committed
Resolve markdown crash for invalid note reference
Issue originally reported here: #654
1 parent a39b0bb commit f7bb997

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/rdoc/markdown.kpeg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@
403403
# the note order list for proper display at the end of the document.
404404

405405
def note_for ref
406+
raise ParseError, "invalid note reference: #{ref}" unless @note_order
407+
406408
@note_order << ref
407409

408410
label = @note_order.length

lib/rdoc/markdown.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ def note label
788788
# the note order list for proper display at the end of the document.
789789

790790
def note_for ref
791+
raise ParseError, "invalid note reference: #{ref}" unless @note_order
792+
791793
@note_order << ref
792794

793795
label = @note_order.length

test/rdoc/rdoc_markdown_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,16 @@ def test_parse_note_inline
10021002
assert_equal expected, doc
10031003
end
10041004

1005+
def test_parse_note_invalid_reference
1006+
@parser.notes = true
1007+
1008+
error = assert_raise RDoc::Markdown::ParseError do
1009+
parse "[[^0]\n"
1010+
end
1011+
1012+
assert_equal "invalid note reference: 0", error.message
1013+
end
1014+
10051015
def test_parse_note_no_notes
10061016
@parser.notes = false
10071017

0 commit comments

Comments
 (0)