Skip to content

Truly independent web browser

LibWeb: Use the HTML hyperlink URL steps for MathML `<a>` elements

Tim Ledbetter108fb032dadf
diff --git a/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp b/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
index 5acd076aab6..97736dbb0d7 100644
--- a/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
+++ b/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
@@ -5,8 +5,6 @@
*/
#include <LibWeb/Bindings/MathMLAnchorElement.h>
-#include <LibWeb/DOM/Document.h>
-#include <LibWeb/MathML/AttributeNames.h>
#include <LibWeb/MathML/MathMLAnchorElement.h>
namespace Web::MathML {
@@ -20,58 +18,4 @@ MathMLAnchorElement::MathMLAnchorElement(DOM::Document& document, DOM::Qualified
MathMLAnchorElement::~MathMLAnchorElement() = default;
-// https://w3c.github.io/mathml-core/#dom-mathmlanchorelement-href
-Utf16String MathMLAnchorElement::href() const
-{
- // The href getter steps are:
-
- // 1. Reinitialize url.
- reinitialize_url();
-
- // 2. Let url be this's url.
- // 3. If url is null and this has no href content attribute, then return the empty string.
- if (!m_url.has_value() && !has_attribute(MathML::AttributeNames::href))
- return {};
-
- // 4. Otherwise, if url is null, then return this's href content attribute's value.
- else if (!m_url.has_value())
- return get_attribute_value(MathML::AttributeNames::href);
-
- // 5. Return url, serialized.
- auto serialized_url = m_url->serialize();
- return Utf16String::from_ascii_without_validation(serialized_url.bytes());
-}
-
-// https://w3c.github.io/mathml-core/#dom-mathmlanchorelement-href
-void MathMLAnchorElement::set_href(Utf16String const& href)
-{
- set_attribute_value(HTML::AttributeNames::href, href);
-}
-
-// https://w3c.github.io/mathml-core/#dfn-set-the-url
-void MathMLAnchorElement::set_the_url()
-{
- // 1. If this element's href content attribute is absent, then return.
- auto href = attribute(MathML::AttributeNames::href);
- if (!href.has_value())
- return;
-
- // 2. Let url be the result of encoding-parsing a URL given this element's href content attribute's value, relative
- // to this element's node document.
- auto url = document().encoding_parse_url(*href);
-
- // 3. If url is not failure, then set this's url to url.
- if (url.has_value())
- m_url = url.release_value();
-}
-
-// https://w3c.github.io/mathml-core/#dfn-update-href
-void MathMLAnchorElement::update_href()
-{
- // To update href for a MathMLAnchorElement, set the element's href content attribute's value to the element's url,
- // serialized.
- auto serialized_url = m_url->serialize();
- hyperlink_element_utils_element().set_attribute_value(MathML::AttributeNames::href, Utf16String::from_ascii_without_validation(serialized_url.bytes()));
-}
-
}
diff --git a/Libraries/LibWeb/MathML/MathMLAnchorElement.h b/Libraries/LibWeb/MathML/MathMLAnchorElement.h
index b45039ecc52..9df30d624e4 100644
--- a/Libraries/LibWeb/MathML/MathMLAnchorElement.h
+++ b/Libraries/LibWeb/MathML/MathMLAnchorElement.h
@@ -6,31 +6,28 @@
#pragma once
-#include <LibWeb/HTML/HyperlinkElementUtils.h>
+#include <LibWeb/HTML/HTMLHyperlinkElementUtils.h>
#include <LibWeb/MathML/MathMLElement.h>
namespace Web::MathML {
+// AD-HOC: MathML Core's set the url steps do not set the url to null first, so href would keep returning the old URL
+// after the href attribute is removed. This shares the HTML steps instead, which do.
class MathMLAnchorElement final
: public MathMLElement
- , public HTML::HyperlinkElementUtils {
+ , public HTML::HTMLHyperlinkElementUtils {
WEB_WRAPPABLE(MathMLAnchorElement, MathMLElement);
GC_DECLARE_ALLOCATOR(MathMLAnchorElement);
public:
virtual ~MathMLAnchorElement() override;
- Utf16String href() const;
- void set_href(Utf16String const&);
-
private:
MathMLAnchorElement(DOM::Document&, DOM::QualifiedName);
// ^HTML::HTMLHyperlinkElementUtils
virtual DOM::Element& hyperlink_element_utils_element() override { return *this; }
virtual DOM::Element const& hyperlink_element_utils_element() const override { return *this; }
- virtual void update_href() override;
- virtual void set_the_url() override;
};
}
diff --git a/Tests/LibWeb/Text/expected/MathML/MathMLAnchorElement.txt b/Tests/LibWeb/Text/expected/MathML/MathMLAnchorElement.txt
index e815f84b329..caea6132b27 100644
--- a/Tests/LibWeb/Text/expected/MathML/MathMLAnchorElement.txt
+++ b/Tests/LibWeb/Text/expected/MathML/MathMLAnchorElement.txt
@@ -1,2 +1,3 @@
<a> tag inside <math> is: MathMLAnchorElement
Its href is: http://example.com/
+Its href after removing the href attribute is: ""
diff --git a/Tests/LibWeb/Text/input/MathML/MathMLAnchorElement.html b/Tests/LibWeb/Text/input/MathML/MathMLAnchorElement.html
index 25a2462bcd3..77c23be176e 100644
--- a/Tests/LibWeb/Text/input/MathML/MathMLAnchorElement.html
+++ b/Tests/LibWeb/Text/input/MathML/MathMLAnchorElement.html
@@ -7,6 +7,8 @@
test(() => {
println(`<a> tag inside <math> is: ${target.constructor.name}`);
println(`Its href is: ${target.href}`);
-
+ target.removeAttribute("href");
+ println(`Its href after removing the href attribute is: "${target.href}"`);
+
});
</script>