mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Check for Svg & MathML tags in stack of open elements scope
list & button scope need to check svg & mathml elements besides the list from s_base_list see https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope
This commit is contained in:
parent
125b13a0cb
commit
e6831003c6
Notes:
github-actions[bot]
2025-10-10 11:10:30 +00:00
Author: https://github.com/lpas
Commit: e6831003c6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6065
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/gmta
4 changed files with 28 additions and 15 deletions
|
|
@ -7,7 +7,9 @@
|
|||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
#include <LibWeb/HTML/Parser/StackOfOpenElements.h>
|
||||
#include <LibWeb/MathML/TagNames.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/SVG/TagNames.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
|
@ -20,20 +22,24 @@ void StackOfOpenElements::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_elements);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const& list) const
|
||||
bool StackOfOpenElements::has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const& list, CheckMathAndSVG check_math_and_svg) const
|
||||
{
|
||||
for (auto const& element : m_elements.in_reverse()) {
|
||||
if (element->local_name() == tag_name)
|
||||
return true;
|
||||
if (list.contains_slow(element->local_name()))
|
||||
return false;
|
||||
if (check_math_and_svg == CheckMathAndSVG::Yes && element->namespace_uri() == Namespace::SVG && element->local_name().is_one_of(SVG::TagNames::foreignObject, SVG::TagNames::desc, SVG::TagNames::title))
|
||||
return false;
|
||||
if (check_math_and_svg == CheckMathAndSVG::Yes && element->namespace_uri() == Namespace::MathML && element->local_name().is_one_of(MathML::TagNames::mi, MathML::TagNames::mo, MathML::TagNames::mn, MathML::TagNames::ms, MathML::TagNames::mtext, MathML::TagNames::annotation_xml))
|
||||
return false;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope(FlyString const& tag_name) const
|
||||
{
|
||||
return has_in_scope_impl(tag_name, s_base_list);
|
||||
return has_in_scope_impl(tag_name, s_base_list, CheckMathAndSVG::Yes);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_scope_impl(DOM::Element const& target_node, Vector<FlyString> const& list) const
|
||||
|
|
@ -43,6 +49,10 @@ bool StackOfOpenElements::has_in_scope_impl(DOM::Element const& target_node, Vec
|
|||
return true;
|
||||
if (list.contains_slow(element->local_name()))
|
||||
return false;
|
||||
if (element->namespace_uri() == Namespace::SVG && element->local_name().is_one_of(SVG::TagNames::foreignObject, SVG::TagNames::desc, SVG::TagNames::title))
|
||||
return false;
|
||||
if (element->namespace_uri() == Namespace::MathML && element->local_name().is_one_of(MathML::TagNames::mi, MathML::TagNames::mo, MathML::TagNames::mn, MathML::TagNames::ms, MathML::TagNames::mtext, MathML::TagNames::annotation_xml))
|
||||
return false;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
@ -56,12 +66,12 @@ bool StackOfOpenElements::has_in_button_scope(FlyString const& tag_name) const
|
|||
{
|
||||
auto list = s_base_list;
|
||||
list.append("button"_fly_string);
|
||||
return has_in_scope_impl(tag_name, list);
|
||||
return has_in_scope_impl(tag_name, list, CheckMathAndSVG::Yes);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_table_scope(FlyString const& tag_name) const
|
||||
{
|
||||
return has_in_scope_impl(tag_name, { "html"_fly_string, "table"_fly_string, "template"_fly_string });
|
||||
return has_in_scope_impl(tag_name, { "html"_fly_string, "table"_fly_string, "template"_fly_string }, CheckMathAndSVG::No);
|
||||
}
|
||||
|
||||
bool StackOfOpenElements::has_in_list_item_scope(FlyString const& tag_name) const
|
||||
|
|
@ -69,7 +79,7 @@ bool StackOfOpenElements::has_in_list_item_scope(FlyString const& tag_name) cons
|
|||
auto list = s_base_list;
|
||||
list.append("ol"_fly_string);
|
||||
list.append("ul"_fly_string);
|
||||
return has_in_scope_impl(tag_name, list);
|
||||
return has_in_scope_impl(tag_name, list, CheckMathAndSVG::Yes);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-select-scope
|
||||
|
|
|
|||
|
|
@ -63,7 +63,12 @@ public:
|
|||
void visit_edges(JS::Cell::Visitor&);
|
||||
|
||||
private:
|
||||
bool has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const&) const;
|
||||
enum class CheckMathAndSVG : u8 {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
bool has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const&, CheckMathAndSVG) const;
|
||||
bool has_in_scope_impl(DOM::Element const& target_node, Vector<FlyString> const&) const;
|
||||
|
||||
Vector<GC::Ref<DOM::Element>> m_elements;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 54 tests
|
||||
|
||||
50 Pass
|
||||
4 Fail
|
||||
54 Pass
|
||||
Pass html5lib_tests10.html 33cab27b810c8329105a4447f7767307577cb52f
|
||||
Pass html5lib_tests10.html b833b22c2ce59749e320b26fbc4d277bc015f261
|
||||
Pass html5lib_tests10.html 5159857bc8326870c92e525f000abe74b51f9104
|
||||
|
|
@ -34,12 +33,12 @@ Pass html5lib_tests10.html 3cffa6d987cfd48c6cd5f9e7d198ca0e79b6cdb8
|
|||
Pass html5lib_tests10.html f89f8c14aeaa1d3107b6aa6d87fbf10e8fd5f8c3
|
||||
Pass html5lib_tests10.html 663691222288a8f734149fba4f1b7ff5bb201df0
|
||||
Pass html5lib_tests10.html dbe5123aed0264b7fe421fea4b9bc5bd304cc596
|
||||
Fail html5lib_tests10.html 982e01ebddec435aeb2dc0f23fa77e4201a38b28
|
||||
Fail html5lib_tests10.html b613b907ffa87da6f3076a24ad775843e5c2a43a
|
||||
Pass html5lib_tests10.html 982e01ebddec435aeb2dc0f23fa77e4201a38b28
|
||||
Pass html5lib_tests10.html b613b907ffa87da6f3076a24ad775843e5c2a43a
|
||||
Pass html5lib_tests10.html 4553fc5ae2782aef4100d8db614041e42c3612e9
|
||||
Pass html5lib_tests10.html 6c10b9811a0d228cf26bc0b55ee12c7d99926270
|
||||
Fail html5lib_tests10.html ee2de7753d6594fbf05d321b24e2c8bb6f2323c6
|
||||
Fail html5lib_tests10.html 225170b3f08201a11d43f153fa3c8a041173b55f
|
||||
Pass html5lib_tests10.html ee2de7753d6594fbf05d321b24e2c8bb6f2323c6
|
||||
Pass html5lib_tests10.html 225170b3f08201a11d43f153fa3c8a041173b55f
|
||||
Pass html5lib_tests10.html 716a01ee7d076876318395625e08e555065fc3b0
|
||||
Pass html5lib_tests10.html 3c5cc236386d2d4a16d14e5c65da7edd26697a43
|
||||
Pass html5lib_tests10.html 6c3447a16060d2805f8c969ec0a7b5c551468f25
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ Harness status: OK
|
|||
|
||||
Found 2 tests
|
||||
|
||||
1 Pass
|
||||
1 Fail
|
||||
Fail html5lib_tests12.html 95751b82f57d4feaaf06d208d57b7f6cc4d5fef5
|
||||
2 Pass
|
||||
Pass html5lib_tests12.html 95751b82f57d4feaaf06d208d57b7f6cc4d5fef5
|
||||
Pass html5lib_tests12.html 411c792cef85cbb029d5c91f4a2142751a319bc2
|
||||
Loading…
Add table
Add a link
Reference in a new issue