fix: prevent text starting with URL from being misidentified as link (#2975)
CI / format (push) Has been cancelled
CI / test (push) Has been cancelled
CI / packaging (push) Has been cancelled

Dart's Uri.tryParse is very permissive and will successfully parse
strings like "https://example.com some extra text" as valid absolute
URIs. This caused the receiver to incorrectly classify any message
beginning with a URL as a link, even when it contained additional
non-URL text.

Add a whitespace check before URI parsing so that only messages
consisting entirely of a single URL (with optional surrounding
whitespace) are treated as links.

Fixes #2904

Co-authored-by: easonysliu <easonysliu@tencent.com>
This commit is contained in:
eason
2026-03-19 00:39:17 +08:00
committed by GitHub
parent 3ec2d77875
commit 9e4a5985b5
+1 -1
View File
@@ -46,7 +46,7 @@ class ReceivePageVm {
required this.onAccept,
required this.onDecline,
required this.onClose,
}) : isLink = message != null && (Uri.tryParse(message)?.isAbsolute ?? false);
}) : isLink = message != null && !message.trim().contains(RegExp(r'\s')) && (Uri.tryParse(message.trim())?.isAbsolute ?? false);
}
class ReceivePage extends StatefulWidget {