Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError when parsing unfinished-link-like text #98

Closed
pelid opened this issue May 25, 2020 · 3 comments
Closed

IndexError when parsing unfinished-link-like text #98

pelid opened this issue May 25, 2020 · 3 comments
Labels

Comments

@pelid
Copy link

pelid commented May 25, 2020

Got unexpected IndexError during rendering of preview for user input. Steps to reproduce are below:

import mistletoe

mistletoe.markdown('# Header with [link](')
Traceback (most recent call last):
  ....
  File ".../site-packages/mistletoe/core_tokens.py", line 206, in match_link_dest
    if string[offset] == '<':
IndexError: string index out of range

Looks like a bug.

Was used mistletoe of version 0.7.2.

@pbodnar
Copy link
Collaborator

pbodnar commented Jul 5, 2020

Hi @pelid, the # Header with [link]( from your testing input is not a valid markdown - the link code is not finished, so the parsing logically fails. So is your requirement to return some nice error from mistletoe, or possibly to fallback to rendering a simple text instead? I would see this as a feature request then.

@fr3aker
Copy link

fr3aker commented Jan 23, 2022

I don't know what the best behaviour would be, but a random exception is likely the worst possible solution. A better behaviour would be a sane, catchable mistletoe exception on invalid markdown. However, it could be argued that it is just text that, on first sight, looks like possibly markdown, while it is in fact just text. It could be a weird smiley: )[<>](. Would it be illegal to have this in a markdown text?

@pbodnar pbodnar added bug and removed enhancement labels Jan 29, 2022
@pbodnar pbodnar changed the title IndexError IndexError when parsing unfinished-link-like text Jan 29, 2022
pbodnar added a commit that referenced this issue Feb 4, 2022
Output from `shift_whitespace()` was not checked at 2 places.
@pbodnar
Copy link
Collaborator

pbodnar commented Feb 4, 2022

Fixed in the master. This turned out to be a very simple one. :) So I don't even add unit tests this time.

@pbodnar pbodnar closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants