Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 481743afd51bd480c6a0a678cf7a835713726fc0
https://github.com/WebKit/WebKit/commit/481743afd51bd480c6a0a678cf7a835713726fc0
Author: Chris Dumez <[email protected]>
Date: 2026-06-22 (Mon, 22 Jun 2026)
Changed paths:
M Source/WebCore/dom/Position.cpp
M Source/WebCore/dom/Position.h
M Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp
Log Message:
-----------
Position::equals() compares against the wrong position's offset for
after-children anchors
https://bugs.webkit.org/show_bug.cgi?id=317571
Reviewed by Anne van Kesteren.
Position::equals() is the cross-anchor-type comparison used by
VisiblePosition::operator==,
AXObjectCache text navigation, and editing commands. When comparing a position
whose anchor
type is PositionIsAfterChildren against a PositionIsOffsetInAnchor position on
the same node,
the comparison tested the child count against *this*
position's m_offset. For an
after-children position m_offset is meaningless (it is 0, set by the
AnchorType-only
constructor), so the predicate degenerated to "countChildNodes() == 0". As a
result two
positions that describe the same DOM location — e.g. (div, AfterChildren) and
(div, 3) for a
div with three children — compared unequal, and the comparison was asymmetric
with the
correct PositionIsOffsetInAnchor vs PositionIsAfterChildren branch.
Fix this by comparing against other.m_offset, mirroring the symmetric branch.
Latent since
the function was introduced in 169247@main (213c76d42579) in 2015.
Test: Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp
* Source/WebCore/dom/Position.cpp:
(WebCore::Position::equals const):
* Source/WebCore/dom/Position.h:
* Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp:
(TestWebKitAPI::TEST(Position, EqualsAfterChildrenVersusOffsetInAnchor)):
Canonical link:
https://flagged.apple.com:443/proxy?t2=Dw2E4c9dS4&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzE1NTk1QG1haW4=&emid=5afd57db-7e2f-4085-b832-278a808bee09&c=11
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications