marked icon indicating copy to clipboard operation
marked copied to clipboard

GFM protocol autolink starts right after `<`, linking URLs inside non-autolink angle brackets

Open philppplik opened this issue 1 month ago • 1 comments

Marked version: 18.1.1 Markdown flavor: GitHub Flavored Markdown (default)

Description

Same root cause as #4118, but for the http:// / https:// case, which is still reproducible on 18.1.1. No existing issue that I could find for the protocol variant.

Expectation

<https://example.com/foo bar> is not a CommonMark autolink (link destinations can't contain spaces), and a GFM extended autolink "can only come at the beginning of a line, after whitespace, or any of the delimiting characters *, _, ~, and (" — < is not one of them. GitHub renders it as plain text:

<p>&lt;https://example.com/foo bar&gt;</p>

Result

marked.parse('<https://example.com/foo bar>')
<p>&lt;<a href="https://example.com/foo">https://example.com/foo</a> bar&gt;</p>

The lexer emits a link token with autolink: true for https://example.com/foo even though it directly follows <, so a chunk of a non-autolink gets linked and the link text misrepresents what was written (the bar> part is dropped from the link but the visible text suggests the whole bracket was a URL).

#4118 covered the www. case (<www.example.com>); the protocol case after < still links on 18.1.1.

philppplik avatar Oct 21 '26 04:10 philppplik

It seems to only autolink for GFM not CommonMark which it should since GFM does make it a link

Marked v18.1.1 gfm: true demo

GFM demo

Marked v18.1.1 gfm: false demo

CommonMark demo

UziTech avatar Oct 21 '26 05:10 UziTech