miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
811 stars 113 forks source link

Failure to parse paragraph containing just "[" #130

Closed fr3aker closed 2 years ago

fr3aker commented 2 years ago

Trying to parse a text that ends with \n\n[ causes a StopIteration exception. Tested on v0.8.1.

>>> from mistletoe import Document
>>> Document("\n\n[")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python3.9/site-packages/mistletoe/block_token.py", line 150, in __init__
    self.children = tokenize(lines)
  File "/lib/python3.9/site-packages/mistletoe/block_token.py", line 49, in tokenize
    return tokenizer.tokenize(lines, _token_types)
  File "/lib/python3.9/site-packages/mistletoe/block_tokenizer.py", line 51, in tokenize
    return make_tokens(tokenize_block(iterable, token_types))
  File "/lib/python3.9/site-packages/mistletoe/block_tokenizer.py", line 67, in tokenize_block
    result = token_type.read(lines)
  File "/lib/python3.9/site-packages/mistletoe/block_token.py", line 311, in read
    line_buffer = [next(lines)]
  File "/lib/python3.9/site-packages/mistletoe/block_tokenizer.py", line 16, in __next__
    raise StopIteration
StopIteration
pbodnar commented 2 years ago

@fr3aker, thanks for reporting.

Here are my remarks explaining why I've changed the issue title a bit:

So it looks like a problem with parsing footnotes (footlinks) once again - might be related to #124. I will have a look at it.

pbodnar commented 2 years ago

OK, so hopefully fixed now, all tests, including python -m test.specification are passing. I also added some remarks in b47d16ca6e3049c0f22773fd0f942f40e4adf39d.

I cannot imagine any negative side-effects of this simple fix, yet some thorough testing of the master branch version is welcome.

fr3aker commented 2 years ago

Took me a while to test this but I finally found time to and it's working very well now. I haven't seen any more parsing errors with 0.8.2! Thank you!

pbodnar commented 2 years ago

@fr3aker, thanks for looking at it. :)