Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rdoc/markdown.kpeg
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@
# the note order list for proper display at the end of the document.

def note_for ref
raise ParseError, "invalid note reference: #{ref}" unless @note_order
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the markdown below is valid, but currently fails. Valid markdown shouldn't raise ParseError.

[foo[^1]bar]

[^1]: footnote

In def parse markdown, there's a source code comment:

# using note_order on the first pass would be a bug
@note_order      = []

The reported error occurs in the first pass (peg_parse 'References'), so referencing @note_order is already a bug. I think just returning nil is better in this case.

# No-op when called in the `References` pass
return unless @note_order

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feedback!

I assume, this is fixed now.


@note_order << ref

label = @note_order.length
Expand Down
2 changes: 2 additions & 0 deletions lib/rdoc/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ def note label
# the note order list for proper display at the end of the document.

def note_for ref
raise ParseError, "invalid note reference: #{ref}" unless @note_order
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a valid problem. But different?

I'm proposing a solution in a separate PR:
#1713


@note_order << ref

label = @note_order.length
Expand Down
10 changes: 10 additions & 0 deletions test/rdoc/rdoc_markdown_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,16 @@ def test_parse_note_inline
assert_equal expected, doc
end

def test_parse_note_invalid_reference
@parser.notes = true

error = assert_raise RDoc::Markdown::ParseError do
parse "[[^0]\n"
end

assert_equal "invalid note reference: 0", error.message
end

def test_parse_note_no_notes
@parser.notes = false

Expand Down