Skip to content

Index out of range during parsing #225

@danpalmer

Description

@danpalmer

I've found a markdown document that causes a fatal error when parsing. While the document itself is fairly useless, I feel like the library should attempt to never fatal error, as this makes detecting and recovering from errors impossible in code that uses it.

Example code:

let text = try String(contentsOfFile: "example.md")
_ = Document(parsing: text, options: [.parseBlockDirectives, .parseSymbolLinks])

This crashes. It looks like it's something to do with CRLF line endings because this does not crash:

var text = try String(contentsOfFile: "example.md")
text = text.replacingOccurrences(of: "\r\n", with: "\n")
_ = Document(parsing: text, options: [.parseBlockDirectives, .parseSymbolLinks])

The example file that triggers this is attached. I am not pasting it in because it's line ending specific.

example.md

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions