Skip to content

Commit 43f58e1

Browse files
browstudioclaude
committed
fix(mobile): respect escapes around normalized bare links
Peel trailing backslashes again whenever stripping punctuation or an emphasis delimiter exposes one, so `*https://example.com/a\**` still becomes a link. Leave an escaped `\<url>` alone instead of rewriting it as an autolink; its URL is linked as a bare link and the `<` stays literal. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 7c0e477 commit 43f58e1

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎mobile/lib/features/channels/message_content/link_normalizer.dart‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,12 @@ String _normalizeLinkSegment(String segment) {
273273
}
274274

275275
String _normalizeProseLinks(String segment) {
276+
// An escaped `\<` is literal, not an autolink; its URL stays a bare link.
276277
var normalized = segment.replaceAllMapped(
277278
_autolinkPattern,
278-
(match) => '[${match[1]}](${match[1]})',
279+
(match) => _isEscaped(segment, match.start)
280+
? match[0]!
281+
: '[${match[1]}](${match[1]})',
279282
);
280283
normalized = normalized.replaceAllMapped(
281284
_bareLinkPattern,
@@ -293,14 +296,18 @@ String _normalizeBareLink(String segment, Match match) {
293296

294297
// A trailing backslash escapes what follows or breaks the line; it is never
295298
// part of the destination, and the renderer would read it as an escape.
299+
// Peel it again whenever stripping punctuation or a delimiter exposes one.
296300
// Scan back rather than match `\\+$`, which retries from every offset.
297-
var urlEnd = url.length;
298-
while (urlEnd > 0 && url.codeUnitAt(urlEnd - 1) == _backslashUnit) {
299-
urlEnd--;
301+
void peelBackslashes() {
302+
var urlEnd = url.length;
303+
while (urlEnd > 0 && url.codeUnitAt(urlEnd - 1) == _backslashUnit) {
304+
urlEnd--;
305+
}
306+
trailing = '${url.substring(urlEnd)}$trailing';
307+
url = url.substring(0, urlEnd);
300308
}
301-
trailing = url.substring(urlEnd);
302-
url = url.substring(0, urlEnd);
303309

310+
peelBackslashes();
304311
if (isBuzzUrl) {
305312
final outsidePunctuation = _trailingPunctuationPattern.firstMatch(url);
306313
if (outsidePunctuation != null) {
@@ -312,6 +319,7 @@ String _normalizeBareLink(String segment, Match match) {
312319
var strippedDelimiter = true;
313320
while (strippedDelimiter) {
314321
strippedDelimiter = false;
322+
peelBackslashes();
315323
for (final delimiter in _markdownDelimiters) {
316324
if (url.endsWith(delimiter) &&
317325
_hasUnclosedMarkdownDelimiter(
@@ -331,6 +339,7 @@ String _normalizeBareLink(String segment, Match match) {
331339
if (punctuation != null) {
332340
url = url.substring(0, punctuation.start);
333341
trailing = '${punctuation[0]}$trailing';
342+
peelBackslashes();
334343
}
335344
}
336345

‎mobile/test/features/channels/message_content_test.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ void main() {
517517
// A bare link's trailing backslash stays outside the link.
518518
(r'see https://example.com/a\', 'see '),
519519
(r'in buzz://channel/9f18f3c6-b5e5-453d-b36d-65487913be0b.\', r'.\'),
520+
(r'*https://example.com/a\**', '*'),
521+
(r'see \<https://example.com/b>', 'see <'),
520522
(
521523
'![shot \\#1](https://example.com/a.png)\n'
522524
'![shot \\#2](https://example.com/b.png)',

0 commit comments

Comments
 (0)