miyuchina / mistletoe

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

exception when trying to parse incomplete link #129

Closed fr3aker closed 2 years ago

fr3aker commented 2 years ago

Trying to parse the string [text]( results in an IndexError. Tested on v0.8.1.

>>> from mistletoe import Document
>>> Document("[text](")
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 88, in make_tokens
    token = token_type(result)
  File "/lib/python3.9/site-packages/mistletoe/block_token.py", line 303, in __init__
    super().__init__(content, span_token.tokenize_inner)
  File "/lib/python3.9/site-packages/mistletoe/block_token.py", line 123, in __init__
    self.children = tokenize_func(lines)
  File "/lib/python3.9/site-packages/mistletoe/span_token.py", line 33, in tokenize_inner
    return tokenizer.tokenize(content, _token_types)
  File "/lib/python3.9/site-packages/mistletoe/span_tokenizer.py", line 8, in tokenize
    tokens = find_tokens(string, token_types, fallback_token)
  File "/lib/python3.9/site-packages/mistletoe/span_tokenizer.py", line 21, in find_tokens
    for m in token_type.find(string):
  File "/lib/python3.9/site-packages/mistletoe/span_token.py", line 92, in find
    return core_tokens.find_core_tokens(string, _root_node)
  File "/lib/python3.9/site-packages/mistletoe/core_tokens.py", line 54, in find_core_tokens
    i = find_link_image(string, i, delimiters, matches, root)
  File "/lib/python3.9/site-packages/mistletoe/core_tokens.py", line 76, in find_link_image
    match = match_link_image(string, offset, delimiter, root)
  File "/lib/python3.9/site-packages/mistletoe/core_tokens.py", line 147, in match_link_image
    match_info = match_link_dest(string, offset+1)
  File "/lib/python3.9/site-packages/mistletoe/core_tokens.py", line 206, in match_link_dest
    if string[offset] == '<':
IndexError: string index out of range
fr3aker commented 2 years ago

sorry, duplicate of https://github.com/miyuchina/mistletoe/issues/98