Review main Abandoned

86875[BUGFIX] Handle links to CE correctly in Linkvalidator

Sybille Peters CR 0 V 0 Normal +75 −9 updated 11/16/24, 16:01

Commit message

Typolinks linking to a page with link to a content element
as anchor of the format t3://page?uid=1#2 were previously
not parsed correctly if the TypoLinkSoftReferenceParser
was used. This was the case for example, for links
in tt_content.header_link.

These links are now parsed correctly which fixes the following
problems:

- 2 links shown instead of one
- links shown as page link but using the ID of the content element
- links incorrectly reported as broken

The reason for the problem was that the
TypoLink(Tag)SoftReferenceParser classes return 2 references for
these kind of links (one for the page, one for the content element).
The method LinkAnalyzer::analyzeTypoLinks (for
TypoLinkTagSoftReferenceParser results) then handled this correctly
by merging the results, but the methd LinkAnalyzer::analyzeLinks
(for TypoLinkSoftReferenceParser) did not.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 4

Review log 1723

  1. Sybille Peters uploaded patch set 1 11/03/24, 13:42

  2. Sybille Peters uploaded patch set 2 11/03/24, 13:43

  3. core-ci voted on patch set 1 V -1 11/03/24, 13:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68997

  4. core-ci voted on patch set 2 V -1 11/03/24, 13:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68998

  5. Sybille Peters uploaded patch set 3 V -1 11/03/24, 14:07

  6. Sybille Peters uploaded patch set 4 11/03/24, 14:09

  7. core-ci voted on patch set 3 V +1 11/03/24, 14:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68999

  8. core-ci voted on patch set 4 V +1 11/03/24, 14:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69000

  9. Simon Schaufelberger voted on patch set 4 CR +1 V +1 11/04/24, 11:15

  10. Garvin Hicking commented on patch set 4 11/04/24, 13:19

    LinkAnalyzer.php:425

    I am unsure about three things here: 1. We have a loop were one check performs a "look-behind". I wonder if there could be (now or in the future) a case where recordRef=tt_content is returned before recordRef=pages, and then $wasPage wouldn't work. I believe for this case it would be better to independently iterate the matched elements twice. Maybe there's some clever array_match/reduce/filter syntax for it, and two foreach's would be too old-school. ;) 2. I understand a hard-coded match for "pages" here, but unsure about "tt_content" and the "#c" prefix. Could there be other tables involved, too, e.g. with custom linkhandlers? 3. Variable naming: I would also prefer full speaking variable names, instead of "$currentR" that might be "referencedPageUID". That could then also be used instead of 'substr' in $foundLinks. Maybe also move `$referencedRecordType = ''` into the `else` part, so better indicate when it remains empty?

    LinkAnalyzer.php:439

    This $type looks a bit problematic. $type is set to '' at the beginning. In the earlier code, $type was iterated in the context of $element of getMatchedElements(), resetting $type always to '' after each iteration. In the new code, $type would always stay to be set to the last type of the previous iteration. Probably using `$linkType->fetchType($reference, '', $keyArr)` would be more logical to always force getting the right type from the current linktypeRegistry? (untested)

    LinkAnalyzer.php:451

    I think at this point `$foundLink['pageAndAnchor']` will always be set, so we wouldn't need the ?? fallback, increasing for clarity (like the other assignments).

    input_header_link_with_page_ce_to_hidden.csv:8

    I would suggest to create a fixture that uses a distinct page uid and content element uid (instead of using both as "1") because then in a test you can't be certain if by accident the page uid or tt_content uid is used twice. (If there is a chance to have this "x#y" notation also in non-tt_content examples, maybe this could be added, too?)
  11. Sybille Peters commented on patch set 4 11/04/24, 13:40

    LinkAnalyzer.php:425 Reply

    I don't know about the internal link handling. I looked in the function analyzeTypolinks and tried to apply similar handling here. Apart from that, I find the function analyzeTypolinks very weird. Perhaps the 2 functions can be refactored and merged. But I really don't know if that should be the scope of this bugfix. I would rather keep this a simple bugfix. For now, the focus is on fixing the bug and backporting it. If we really want to change a lot, perhaps we should look into if the 2 functions analylizeTypolinks and analyizeLinks can be merged or if core functionality can be reused. I am a bit puzzled - should this kind of functionality be also required in other places in the core? 2. This is the same as in analyzeTypolinks You may be right. 3. Variable naming: Should we rename all the variables just for a simple bug fix.

    LinkAnalyzer.php:439 Reply

    You are probably right.

    LinkAnalyzer.php:451 Reply

    ok

    input_header_link_with_page_ce_to_hidden.csv:8 Reply

    good idea
  12. Garvin Hicking commented on patch set 4 11/04/24, 14:20

    LinkAnalyzer.php:425 Reply

    I fully agree, merging or refactoring both methods sounds out of scope to me. As for variables I mostly referred to ones that are added new with this patch, so it would be fair to give those proper names (currentR, 'substr').
  13. Sybille Peters uploaded patch set 5 CR +1 V +1 11/05/24, 07:08

  14. Sybille Peters commented on patch set 4 11/05/24, 07:10

    input_header_link_with_page_ce_to_hidden.csv:8 Reply

    I changed the ids so the uids and pids are all unique. I added some more links in the fixture so we test all of: - hidden ce on hidden page - not hidden ce on hidden page - hidden ce on not hidden page - not hidden ce on not hidden page Also, I added link for sys_file_reference.link Working on rest of the suggestions ....
  15. core-ci voted on patch set 5 V +1 11/05/24, 07:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69076

  16. Sybille Peters uploaded patch set 6 V +1 11/05/24, 08:11

  17. Sybille Peters commented on patch set 6 11/05/24, 08:13

    LinkAnalyzer.php:425 Reply

    I changed the variable naming (point 3). About point 1 and 2 don't really know how to handle them right now.

    LinkAnalyzer.php:439 Reply

    Done

    LinkAnalyzer.php:451 Reply

    Done
  18. core-ci voted on patch set 6 V +1 11/05/24, 08:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69081

  19. Sybille Peters wrote 11/07/24, 12:58

    Topic set to Linkvalidator
  20. Sybille Peters abandoned the change 11/16/24, 16:00

    will use different approach (see last comment), created new patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87004
  21. Sybille Peters commented on patch set 6 11/16/24, 16:00

    LinkAnalyzer.php:425 Reply Unresolved

    I don't see a possibility to find out which of the 2 references the softref parser has split up belong together. In the bug we are trying to solve however, we have fields that do not really need parsing, they contain only the link (with 'type' = 'link' in TCA). So instead of using the softref parsers for type='link' I think we can construct the link record directly from the content. This is an entirely different approach, so I uploaded a new patch and will abandon this one. https://review.typo3.org/c/Packages/TYPO3.CMS/+/87004
  22. Sybille Peters restored the change 11/16/24, 16:00

  23. Sybille Peters abandoned the change 11/16/24, 16:01

    Use different approach (see last comment), new patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87004