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
This commit is contained in:
apporc 2024-11-02 17:26:05 +08:00
parent 9b78d437de
commit ffb3433b5b

View file

@ -523,6 +523,9 @@ public class Browser {
try {
if (isTonsite(url) || isInternalUrl(url, null)) return false;
Uri uri = Uri.parse(url);
if (isAppLinkStyle(uri)) {
url = uri.toString();
} else {
url = Browser.replace(
uri,
uri.getScheme() == null ? "https" : uri.getScheme(),
@ -530,6 +533,7 @@ public class Browser {
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("//");
}
}