miyuchina/mistletoe

Failure to parse paragraph containing just "["

fr3aker opened this issue · 4 comments

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

@fr3aker, thanks for reporting.

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

  • When a paragraph with just [ is present and it is the last thing in text, StopIteration is raised.
  • Otherwise the paragraph is skipped.

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

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

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

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!

@fr3aker, thanks for looking at it. :)