Skip to content
TypeScript

fix(mobile): link URLs with ports and single-label hosts (#13795)

Yash Singhfe6388f01d5a
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 00000000000..29beb22c1cf
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,70 @@
+diff --git a/cpp/md4c/md4c.c b/cpp/md4c/md4c.c
+--- a/cpp/md4c/md4c.c
++++ b/cpp/md4c/md4c.c
+@@ -3908,10 +3908,10 @@
+ int min_components;
+ const MD_CHAR optional_end_char;
+ } URL_MAP[] = {
+- { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
+- { _T('/'), _T('/'), _T("/.-_"), 0, _T('/') }, /* path */
+- { _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
+- { _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
++ { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
++ { _T('/'), _T('/'), _T("/.-_():~%+@&!,;"), 0, _T('/') }, /* path */
++ { _T('?'), _T('&'), _T("&.-+_=().:!~%,;@"), 1, _T('\0') }, /* query */
++ { _T('#'), _T('\0'), _T(".-+_:%~") , 1, _T('\0') } /* fragment */
+ };
+
+ MD_MARK* opener = &ctx->marks[mark_index];
+@@ -3981,8 +3981,11 @@
+ } else if(end < line_end &&
+ ISANYOF(end, URL_MAP[i].allowed_nonalnum_chars) &&
+ md_scan_right_for_resolved_mark(ctx, right_cursor, end, &right_cursor) == NULL &&
+- ((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
+- ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))
++ /* Scheme URLs keep '...' and ':' in the path and query.
++ * Host, e-mail, and www labels stay flanked by alphanumerics. */
++ ((opener->ch == _T(':') && i > 0) ||
++ (((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
++ ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))))
+ {
+ if(CH(end) == URL_MAP[i].delim_char)
+ n_components++;
+@@ -4006,16 +4009,35 @@
+ CH(end) == URL_MAP[i].optional_end_char)
+ end++;
+
+- if(n_components < URL_MAP[i].min_components || n_open_brackets != 0)
++ /* Scheme autolinks allow one host label, so localhost and devbox link.
++ * E-mail and www autolinks still require a dotted host. */
++ if(n_components < (i == 0 && opener->ch == ':' ? 1 : URL_MAP[i].min_components) ||
++ n_open_brackets != 0)
+ return;
+
++ /* Optional port on a scheme autolink: ':' followed by digits. */
++ if(i == 0 && opener->ch == ':' && end + 1 < line_end &&
++ CH(end) == _T(':') && ISDIGIT(end + 1)) {
++ end++;
++ while(end < line_end && ISDIGIT(end))
++ end++;
++ }
++
+ if(opener->ch == '@') /* E-mail autolinks wants only the host. */
+ break;
++ }
++
++ /* GFM leaves a trailing run of punctuation outside the link, including
++ * the sentence dots in "https://example.com/a...". */
++ if(opener->ch == _T(':')) {
++ while(end > opener->end && ISANYOF(end - 1, _T("?!.,:*_~")))
++ end--;
+ }
+
+ /* Verify there's line boundary, whitespace, allowed punctuation or
+ * resolved emphasis mark just after the suspected autolink. */
+- if(end == line_end || ISUNICODEWHITESPACE(end) || ISANYOF(end, _T(")}].!?,;"))) {
++ if(end == line_end || ISUNICODEWHITESPACE(end) ||
++ ISANYOF(end, opener->ch == _T(':') ? _T(")}].!?,;:*_~'\"`<>") : _T(")}].!?,;"))) {
+ right_boundary_ok = TRUE;
+ } else {
+ MD_MARK* right_mark;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8e2feb8d278..707e03bc404 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -108,6 +108,7 @@ patchedDependencies:
[email protected]: 319a9ded5db49c5b5215c511a138b33f44c7ea2972eb418192e8d5342fe75ce6
[email protected]: 0579f8e4dad02bf3183d95b02620358412983c36f9bda7425dc8bcb9643b5ce2
[email protected]: 6e4339347bc5bb3c9ea67d85ff5c814058b211c5750f247aba59d07869a2e787
+ [email protected]: 7f5d2a8c357746316f67c9600034abbe71166ec766df27619a157f40b2c5a23c
[email protected]: 825622aae63a8fb5b904f3c77908a0e216261d727ea171709f2c0b6088422675
[email protected]: bae9878a5bdba94e11c890e5ee164542feb622624fc81c13890063094608216d
[email protected]: 595114f3f9ce8b9f0d99d1aafe5c12c997b7d75ca9add31d46cbedbfe347b8e0
@@ -298,7 +299,7 @@ importers:
version: link:../../packages/contracts
'@t3tools/mobile-markdown-text':
specifier: file:./modules/t3-markdown-text
- version: file:apps/mobile/modules/t3-markdown-text(6f0a94b6f541bbd4be3f343e27991996)
+ version: file:apps/mobile/modules/t3-markdown-text(54829604106ac55999e32558f817d201)
'@t3tools/mobile-review-diff-native':
specifier: file:./modules/t3-review-diff
version: file:apps/mobile/modules/t3-review-diff
@@ -445,7 +446,7 @@ importers:
react-native-nitro-markdown:
specifier: ^0.5.0
react-native-nitro-modules:
specifier: 0.35.9
version: 0.35.9(patch_hash=825622aae63a8fb5b904f3c77908a0e216261d727ea171709f2c0b6088422675)([email protected](@babel/[email protected])(@react-native/[email protected](@babel/[email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])([email protected]))([email protected])
@@ -15082,7 +15083,7 @@ snapshots:
dependencies:
defer-to-connect: 2.0.1
- '@t3tools/mobile-markdown-text@file:apps/mobile/modules/t3-markdown-text(6f0a94b6f541bbd4be3f343e27991996)':
+ '@t3tools/mobile-markdown-text@file:apps/mobile/modules/t3-markdown-text(54829604106ac55999e32558f817d201)':
dependencies:
'@t3tools/client-runtime': link:packages/client-runtime
'@t3tools/shared': link:packages/shared
@@ -15093,7 +15094,7 @@ snapshots:
react: 19.2.3
'@t3tools/mobile-review-diff-native@file:apps/mobile/modules/t3-review-diff': {}
@@ -20677,7 +20678,7 @@ snapshots:
dependencies:
react: 19.2.3
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 0ccd9e4436a..f09f22fc445 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -197,6 +197,8 @@ patchedDependencies:
+ # Link http(s) URLs with a port or a single-label host. md4c otherwise requires a dotted host and stops at ':'.
# Preserve the final layout frame. Backport of [#10171](https://github.com/software-mansion/react-native-reanimated/pull/10171).