Skip to content

Commit 626d961

Browse files
authored
fix: Make www case-sensitive when detecting link starts (#3770)
1 parent e3c0d3e commit 626d961

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/rules.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,15 @@ const inlineGfm: Record<InlineKeys, RegExp> = {
408408
...inlineNormal,
409409
emStrongRDelimAst: emStrongRDelimAstGfm,
410410
emStrongLDelim: emStrongLDelimGfm,
411-
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i')
411+
url: edit(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/)
412+
.replace('protocol', /[fF][tT][pP]|[hH][tT][tT][pP][sS]?/)
412413
.replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/)
413414
.getRegex(),
414415
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
415416
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
416-
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
417+
text: edit(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/)
418+
.replace('protocol', /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/)
419+
.getRegex(),
417420
};
418421

419422
/**

test/specs/new/autolinks.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@
1212

1313
<p><strong><a href="mailto:[email protected]">[email protected]</a></strong></p>
1414

15-
<p><strong><a href="mailto:[email protected]">[email protected]</a></strong></p>
15+
<p><strong><a href="mailto:[email protected]">[email protected]</a></strong></p>
16+
17+
<p><a href="http://www.example.com">www.example.com</a></p>
18+
19+
<p>Www.example.com</p>
20+
21+
<p>WWW.example.com</p>
22+
23+
<p>(See <a href="hTtPS://example.com/fhqwhgads">hTtPS://example.com/fhqwhgads</a>.)</p>

test/specs/new/autolinks.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ hTtP://fOo.CoM
1212

1313
1414

15-
15+
16+
17+
www.example.com
18+
19+
Www.example.com
20+
21+
WWW.example.com
22+
23+
(See hTtPS://example.com/fhqwhgads.)

0 commit comments

Comments
 (0)