diff --git a/Libraries/LibWeb/SVG/SVGImageElement.cpp b/Libraries/LibWeb/SVG/SVGImageElement.cpp index 81f038773b8..b785dc4ccd7 100644 --- a/Libraries/LibWeb/SVG/SVGImageElement.cpp +++ b/Libraries/LibWeb/SVG/SVGImageElement.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,19 @@ void SVGImageElement::attribute_changed(FlyString const& name, Optional auto parsed_value = AttributeParser::parse_coordinate(value.value_or(String {})); MUST(height()->base_val()->set_value(parsed_value.value_or(0))); } else if (name == SVG::AttributeNames::href) { - process_the_url(value); + // https://svgwg.org/svg2-draft/linking.html#XLinkRefAttrs + // For backwards compatibility, elements with an ‘href’ attribute also recognize an ‘href’ attribute in the + // XLink namespace. If the element is in the XLink namespace, it does not recognize an ‘href’ attribute in the + // SVG namespace. When the ‘href’ attribute is present in both the XLink namespace and without a namespace, the + // value of the attribute without a namespace shall be used. The attribute in the XLink namespace shall be ignored. + if (namespace_ == Namespace::XLink && has_attribute_ns({}, name)) + return; + + auto href = value; + if (!namespace_.has_value() && !href.has_value()) + href = get_attribute_ns(SVG::AttributeNames::href, Namespace::XLink); + + process_the_url(href); } } diff --git a/Tests/LibWeb/Ref/data/50x50-red.svg b/Tests/LibWeb/Ref/data/50x50-red.svg new file mode 100644 index 00000000000..7bff125c2dd --- /dev/null +++ b/Tests/LibWeb/Ref/data/50x50-red.svg @@ -0,0 +1,3 @@ + + + diff --git a/Tests/LibWeb/Ref/expected/svg/image-xlink-href-ref.html b/Tests/LibWeb/Ref/expected/svg/image-xlink-href-ref.html new file mode 100644 index 00000000000..9b39a5b876f --- /dev/null +++ b/Tests/LibWeb/Ref/expected/svg/image-xlink-href-ref.html @@ -0,0 +1,4 @@ + + + + diff --git a/Tests/LibWeb/Ref/input/svg/image-prefer-href-to-xlink-href.html b/Tests/LibWeb/Ref/input/svg/image-prefer-href-to-xlink-href.html new file mode 100644 index 00000000000..f4e713c67d5 --- /dev/null +++ b/Tests/LibWeb/Ref/input/svg/image-prefer-href-to-xlink-href.html @@ -0,0 +1,5 @@ + + + + + diff --git a/Tests/LibWeb/Ref/input/svg/image-xlink-href.html b/Tests/LibWeb/Ref/input/svg/image-xlink-href.html new file mode 100644 index 00000000000..db1c1770dee --- /dev/null +++ b/Tests/LibWeb/Ref/input/svg/image-xlink-href.html @@ -0,0 +1,5 @@ + + + + +