mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
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:
parent
9b78d437de
commit
ffb3433b5b
1 changed files with 24 additions and 7 deletions
|
@ -523,13 +523,17 @@ public class Browser {
|
||||||
try {
|
try {
|
||||||
if (isTonsite(url) || isInternalUrl(url, null)) return false;
|
if (isTonsite(url) || isInternalUrl(url, null)) return false;
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
url = Browser.replace(
|
if (isAppLinkStyle(uri)) {
|
||||||
uri,
|
url = uri.toString();
|
||||||
uri.getScheme() == null ? "https" : uri.getScheme(),
|
} else {
|
||||||
null, uri.getHost() != null ? uri.getHost().toLowerCase() : uri.getHost(),
|
url = Browser.replace(
|
||||||
TextUtils.isEmpty(uri.getPath()) ? "/" : uri.getPath()
|
uri,
|
||||||
);
|
uri.getScheme() == null ? "https" : uri.getScheme(),
|
||||||
uri = Uri.parse(url);
|
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");
|
final boolean isIntentScheme = url.startsWith("intent://") || uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("intent");
|
||||||
if (isIntentScheme && !allowIntent) return false;
|
if (isIntentScheme && !allowIntent) return false;
|
||||||
final Intent intent = isIntentScheme ?
|
final Intent intent = isIntentScheme ?
|
||||||
|
@ -830,4 +834,17 @@ public class Browser {
|
||||||
return modifiedUriBuilder.toString();
|
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("//");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue