1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-31 11:31:40 +00:00

First resolve base/href

This commit is contained in:
M66B 2021-10-02 19:48:23 +02:00
parent dc785eeff5
commit 874c8fa647

View file

@ -1247,22 +1247,24 @@ public class HtmlHelper {
} }
static void removeRelativeLinks(Document document) { static void removeRelativeLinks(Document document) {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
Elements b = document.select("base"); Elements b = document.select("base");
String base = (b.size() > 0 ? b.get(0).attr("href") : null); String base = (b.size() > 0 ? b.get(0).attr("href") : null);
for (Element a : document.select("a")) { for (Element a : document.select("a")) {
String href = a.attr("href"); String href = a.attr("href");
if (href.trim().startsWith("#")) { if (!TextUtils.isEmpty(base))
a.tagName("span");
a.removeAttr("href");
} else if (!TextUtils.isEmpty(base))
try { try {
// https://developer.android.com/reference/java/net/URI // https://developer.android.com/reference/java/net/URI
URI u = URI.create(base); href = URI.create(base).resolve(href).toString();
URI r = u.resolve(href); a.attr("href", href);
a.attr("href", r.toString());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} }
if (href.trim().startsWith("#")) {
a.tagName("span");
a.removeAttr("href");
}
} }
} }