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:
parent
dc785eeff5
commit
874c8fa647
1 changed files with 9 additions and 7 deletions
|
@ -1247,21 +1247,23 @@ 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 (!TextUtils.isEmpty(base))
|
||||||
|
try {
|
||||||
|
// https://developer.android.com/reference/java/net/URI
|
||||||
|
href = URI.create(base).resolve(href).toString();
|
||||||
|
a.attr("href", href);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
|
||||||
if (href.trim().startsWith("#")) {
|
if (href.trim().startsWith("#")) {
|
||||||
a.tagName("span");
|
a.tagName("span");
|
||||||
a.removeAttr("href");
|
a.removeAttr("href");
|
||||||
} else if (!TextUtils.isEmpty(base))
|
|
||||||
try {
|
|
||||||
// https://developer.android.com/reference/java/net/URI
|
|
||||||
URI u = URI.create(base);
|
|
||||||
URI r = u.resolve(href);
|
|
||||||
a.attr("href", r.toString());
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
Log.w(ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue