Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Harden XPath query to limit search for page tree node #479

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eliashaeussler
Copy link
Contributor

Even if page tree nodes are queried from a given context node, the currently used XPath query searches for all elements in the document instead. That's because of the // syntax, which searches in the whole document, regardless of which context is given. This may lead to possible test failures in case the queried node text appears multiple times in the document, for example when trying to access the root page tree node whose text appears twice on the page – next to the TYPO3 logo in the topbar and as root node in the page tree. With the current implementation, the XPath query would match the text in the topbar instead of the text of the root node.

In order to avoid such behaviors and actually limit the XPath query to the given context, it is now prefixed with a dot (.). In addition, only following siblings of the current node are included since page tree nodes are presented as flat node structure. This way, the current context is now actually taken into account.

As an additional fix, property accesses of static properties in AbstractPageTree is now changed from self:: to static:: to properly respect overridden properties in extended classes. This is especially necessary for the overridden properties in TYPO3 core's FileTree.

Patch in TYPO3 core: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80039

💡 If this PR will be merged, I'll update the TYPO3 core patch accordingly.

@oliverklee
Copy link
Contributor

As an additional fix, property accesses of static properties in AbstractPageTree is now changed from self:: to static:: to properly respect overridden properties in extended classes. This is especially necessary for the overridden properties in TYPO3 core's FileTree.

I propose we move this to a separate change (following the "only one kind of change per PR" rule).

@eliashaeussler
Copy link
Contributor Author

As an additional fix, property accesses of static properties in AbstractPageTree is now changed from self:: to static:: to properly respect overridden properties in extended classes. This is especially necessary for the overridden properties in TYPO3 core's FileTree.

I propose we move this to a separate change (following the "only one kind of change per PR" rule).

Sure, we can do that.

The reason why I combined both changes into one PR is because the change of the XPath query makes tests in TYPO3 core fail due to the fact those static properties are not accessed correctly. This additional change was necessary to make tests in https://review.typo3.org/c/Packages/TYPO3.CMS/+/80039 green again 😉

But I'm also totally fine with splitting into two separate PRs.

@sbuerk
Copy link
Collaborator

sbuerk commented Jul 16, 2023

@eliashaeussler Don't act for now !!!

In TF we usually do not merge it as merge-commits, so as long as we
have dedicated commits for each thing it may be okay. Not qualified
reviewed it yet, will do this later.

The comment from @oliverklee in general is valid and a good advice
generally (makes it possible to merge one thing and eventually
continue on the rest).

In the worst case we (I) would cherry-pick the commits anyway.

Only point on quick view, it would be nice to have one or to sentence
in the commit message for 9f47062.

@eliashaeussler
Copy link
Contributor Author

@sbuerk Do you need anything else from me to continue here? :)

Even if page tree nodes are queried from a given context node, the
used XPath query searches for all elements in the document because
of the `//` syntax. This may lead to possible test failures in case
the queried node text appears multiple times in the document.

In order to avoid such behaviors and actually limit the XPath query
to the given context, it is now prefixed with a dot (`.`). In
addition, only following siblings of the current node are included
since page tree nodes are presented as flat node structure. This
way, the current context is now actually taken into account.
This changes all property accesses within AbstractPageTree to
use static instead of self. Since the class is abstract and
therefore subject to class inheritance, its properties may also
change in subclasses. Using self to access them would hide
potentially overridden properties (late static binding).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants