Sanitize amp URIs

This commit is contained in:
M66B 2020-05-02 16:36:14 +02:00
parent 64170b99f2
commit 62bc889b12
1 changed files with 24 additions and 0 deletions

View File

@ -5500,6 +5500,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
!TextUtils.isEmpty(uri.getQueryParameter("url"))) {
changed = true;
url = Uri.parse(uri.getQueryParameter("url"));
} else if ("https".equals(uri.getScheme()) &&
"www.google.com".equals(uri.getHost()) &&
uri.getPath() != null &&
uri.getPath().startsWith("/amp/")) {
// https://blog.amp.dev/2017/02/06/whats-in-an-amp-url/
Uri result = null;
String u = uri.toString();
u = u.replace("https://www.google.com/amp/", "");
int p = u.indexOf("/");
while (p > 0) {
String segment = u.substring(0, p);
if (segment.contains(".")) {
result = Uri.parse("https://" + u);
break;
}
u = u.substring(p + 1);
p = u.indexOf("/");
}
changed = (result != null);
url = (result == null ? uri : result);
} else
url = uri;