Skip to content

Commit 8baff10

Browse files
nperez0111claude
andcommitted
fix: address CodeRabbit review feedback in linkDetector
- Fix double mailto: prefix for mailto: URLs in linkToken() — values starting with "mailto:" are now classified as "url" not "email" - Support schemeless URLs with ? or # suffixes (e.g. example.com?x=1, example.com#frag) in both SCHEMELESS_RE and isSingleUrl() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ae0a32 commit 8baff10

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/core/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const EMAIL_RE =
5454
// Schemeless URLs: domain.tld with optional port and path
5555
// Hostname: one or more labels separated by dots, TLD is alpha-only 2+ chars
5656
const SCHEMELESS_RE =
57-
/(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?::\d{1,5})?(?:\/[^\s]*)?/g;
57+
/(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?::\d{1,5})?(?:[/?#][^\s]*)?/g;
5858

5959
// ---------------------------------------------------------------------------
6060
// Post-processing helpers
@@ -371,7 +371,7 @@ function isSingleUrl(text: string): boolean {
371371

372372
// Schemeless URLs: hostname.tld with optional port and path
373373
const schemelessFull =
374-
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+([a-zA-Z]{2,})(?::\d{1,5})?(?:\/[^\s]*)?$/;
374+
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+([a-zA-Z]{2,})(?::\d{1,5})?(?:[/?#][^\s]*)?$/;
375375
const match = text.match(schemelessFull);
376376
if (match) {
377377
const tld = match[1].toLowerCase();
@@ -390,7 +390,10 @@ function linkToken(
390390
end: number,
391391
defaultProtocol: string
392392
): LinkMatch {
393-
const type = value.includes("@") && !value.includes("://") ? "email" : "url";
393+
const type =
394+
value.includes("@") && !value.includes("://") && !value.startsWith("mailto:")
395+
? "email"
396+
: "url";
394397
return {
395398
type,
396399
value,

0 commit comments

Comments
 (0)