Skip to content

Commit 7ddd076

Browse files
committed
fix(mobile): autolink full URLs with colons, tildes, and ellipses
- Widen md4c permissive autolink path/query/fragment chars (:~%+@&!,;) - Let scheme URLs keep ':' and '...' inside path and query - Trim trailing sentence punctuation from scheme autolinks, per GFM - Accept more closing punctuation and quotes after scheme URLs
1 parent 9a96324 commit 7ddd076

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

‎patches/[email protected]‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
diff --git a/cpp/md4c/md4c.c b/cpp/md4c/md4c.c
22
--- a/cpp/md4c/md4c.c
33
+++ b/cpp/md4c/md4c.c
4-
@@ -3909,7 +3909,7 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
4+
@@ -3908,10 +3908,10 @@
5+
int min_components;
56
const MD_CHAR optional_end_char;
67
} URL_MAP[] = {
7-
{ _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
8+
- { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
89
- { _T('/'), _T('/'), _T("/.-_"), 0, _T('/') }, /* path */
9-
+ { _T('/'), _T('/'), _T("/.-_()"), 0, _T('/') }, /* path */
10-
{ _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
11-
{ _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
10+
- { _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
11+
- { _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
12+
+ { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
13+
+ { _T('/'), _T('/'), _T("/.-_():~%+@&!,;"), 0, _T('/') }, /* path */
14+
+ { _T('?'), _T('&'), _T("&.-+_=().:!~%,;@"), 1, _T('\0') }, /* query */
15+
+ { _T('#'), _T('\0'), _T(".-+_:%~") , 1, _T('\0') } /* fragment */
1216
};
13-
@@ -4006,9 +4006,20 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
17+
18+
MD_MARK* opener = &ctx->marks[mark_index];
19+
@@ -3981,8 +3981,11 @@
20+
} else if(end < line_end &&
21+
ISANYOF(end, URL_MAP[i].allowed_nonalnum_chars) &&
22+
md_scan_right_for_resolved_mark(ctx, right_cursor, end, &right_cursor) == NULL &&
23+
- ((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
24+
- ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))
25+
+ /* Scheme URLs keep '...' and ':' in the path and query.
26+
+ * Host, e-mail, and www labels stay flanked by alphanumerics. */
27+
+ ((opener->ch == _T(':') && i > 0) ||
28+
+ (((end > line_beg && (ISALNUM(end-1) || CH(end-1) == _T(')'))) || CH(end) == _T('(')) &&
29+
+ ((end+1 < line_end && (ISALNUM(end+1) || CH(end+1) == _T('('))) || CH(end) == _T(')')))))
30+
{
31+
if(CH(end) == URL_MAP[i].delim_char)
32+
n_components++;
33+
@@ -4006,16 +4009,35 @@
1434
CH(end) == URL_MAP[i].optional_end_char)
1535
end++;
1636

@@ -31,4 +51,20 @@ diff --git a/cpp/md4c/md4c.c b/cpp/md4c/md4c.c
3151
+
3252
if(opener->ch == '@') /* E-mail autolinks wants only the host. */
3353
break;
54+
+ }
55+
+
56+
+ /* GFM leaves a trailing run of punctuation outside the link, including
57+
+ * the sentence dots in "https://example.com/a...". */
58+
+ if(opener->ch == _T(':')) {
59+
+ while(end > opener->end && ISANYOF(end - 1, _T("?!.,:*_~")))
60+
+ end--;
3461
}
62+
63+
/* Verify there's line boundary, whitespace, allowed punctuation or
64+
* resolved emphasis mark just after the suspected autolink. */
65+
- if(end == line_end || ISUNICODEWHITESPACE(end) || ISANYOF(end, _T(")}].!?,;"))) {
66+
+ if(end == line_end || ISUNICODEWHITESPACE(end) ||
67+
+ ISANYOF(end, opener->ch == _T(':') ? _T(")}].!?,;:*_~'\"`<>") : _T(")}].!?,;"))) {
68+
right_boundary_ok = TRUE;
69+
} else {
70+
MD_MARK* right_mark;

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)