Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? '';
} while (prevCapZero !== cap[0]);
text = cap[0];
if (cap[1] === 'www.') {
if (cap[1]?.toLowerCase() === 'www.') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly handles case-insensitive www. prefixes. However, the generated href preserves the original casing of the domain (e.g., http://Www.foo.com).

According to RFC 3986, the host component of a URI is case-insensitive. It is a best practice to normalize it to lowercase in the href attribute for consistency and to prevent potential issues. The visible link text should preserve the original user input.

You could consider updating the logic inside this if block to normalize the domain part of the URL. Here's a possible implementation:

// inside the if (cap[1]?.toLowerCase() === 'www.') block
const pathStartIndex = cap[0].search(/[\/?#]/);
const domain = pathStartIndex === -1 ? cap[0] : cap[0].substring(0, pathStartIndex);
const path = pathStartIndex === -1 ? '' : cap[0].substring(pathStartIndex);
href = 'http://' + domain.toLowerCase() + path;

If you apply this change, please remember to update the corresponding test case in test/specs/new/autolinks.html to expect a lowercase href.

href = 'http://' + cap[0];
} else {
href = cap[0];
Expand Down
6 changes: 5 additions & 1 deletion test/specs/new/autolinks.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

<p><a href="hTtP://fOo.CoM">hTtP://fOo.CoM</a></p>

<p><a href="http://www.foo.com">www.foo.com</a></p>

<p><a href="http://Www.foo.com">Www.foo.com</a></p>

<p><del><a href="mailto:hello@email.com">hello@email.com</a></del></p>

<p><strong><a href="mailto:me@example.com">me@example.com</a></strong></p>

<p><strong><a href="mailto:test@test.com">test@test.com</a></strong></p>
<p><strong><a href="mailto:test@test.com">test@test.com</a></strong></p>
6 changes: 5 additions & 1 deletion test/specs/new/autolinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ HTTP://FOO.COM

hTtP://fOo.CoM

www.foo.com

Www.foo.com

~~hello@email.com~~

**me@example.com**

__test@test.com__
__test@test.com__