Skip to content

gfm_autolink: a www. URL inside link text hangs the parser #160

Closed

Description

@JoshKarpel

Describe the bug

context

Parsing a link whose text contains a bare subdomain like www. with no scheme, like see [www.example.com](https://example.com).

bug

The parser hangs:

Input Result
see [www.example.com](https://example.com) hangs
[link *www.example.com*](https://example.org) hangs
[www.example.com](https://example.com) <p><a href="https://example.com">www.example.com</a></p>
[https://example.com](https://example.org) renders correctly
[[email protected]](https://example.org) renders correctly

problem

The link text is arbitrary and might come from an untrusted source that we don't control, so it shouldn't hang the parser.

Reproduce the bug

from markdown_it import MarkdownIt
from mdit_py_plugins.gfm_autolink import gfm_autolink_plugin

md = MarkdownIt("commonmark").use(gfm_autolink_plugin)
md.render("see [www.example.com](https://example.com)")  # never returns

List your environment

mdit-py-plugins 0.6.1, markdown-it-py 4.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions