From ffb3433b5bfc2932f457514406f1124d1bf88027 Mon Sep 17 00:00:00 2001 From: apporc Date: Sat, 2 Nov 2024 17:26:05 +0800 Subject: [PATCH] Fix app link in in app browser(#45064) 1. 'someapp:payload' style url is valid, comforming to 'mailto:xxx' and 'tel:xxx'; 2. the final url parsed out for above is 'someapp:///', which is wrong. Reference: https://bugs.telegram.org/c/45064 --- .../telegram/messenger/browser/Browser.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java index e5d08155d..bfedde2dd 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java @@ -523,13 +523,17 @@ public class Browser { try { if (isTonsite(url) || isInternalUrl(url, null)) return false; Uri uri = Uri.parse(url); - url = Browser.replace( - uri, - uri.getScheme() == null ? "https" : uri.getScheme(), - null, uri.getHost() != null ? uri.getHost().toLowerCase() : uri.getHost(), - TextUtils.isEmpty(uri.getPath()) ? "/" : uri.getPath() - ); - uri = Uri.parse(url); + if (isAppLinkStyle(uri)) { + url = uri.toString(); + } else { + url = Browser.replace( + uri, + uri.getScheme() == null ? "https" : uri.getScheme(), + null, uri.getHost() != null ? uri.getHost().toLowerCase() : uri.getHost(), + TextUtils.isEmpty(uri.getPath()) ? "/" : uri.getPath() + ); + uri = Uri.parse(url); + } final boolean isIntentScheme = url.startsWith("intent://") || uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("intent"); if (isIntentScheme && !allowIntent) return false; final Intent intent = isIntentScheme ? @@ -830,4 +834,17 @@ public class Browser { return modifiedUriBuilder.toString(); } + private static boolean isAppLinkStyle(Uri uri) { + if (uri == null || uri.getScheme() == null) { + return false; + } + + // App links typically have: + // 1. A scheme + // 2. No authority/host + // 3. Scheme-specific part directly after colon + return uri.getHost() == null && + uri.getSchemeSpecificPart() != null && + !uri.getSchemeSpecificPart().startsWith("//"); + } }