Internal links are missing their base path

Created on 25 July 2023, over 1 year ago
Updated 28 August 2023, over 1 year ago

Problem/Motivation

If the request is set in \Drupal\linkchecker\LinkExtractorService::getLinks or \Drupal\linkchecker\Plugin\LinkStatusHandler\Repair301::linkReplace, then the base URL is set to $this->request->getSchemeAndHttpHost() which does not contain the base path, if any. In tests, though, the base path is being added correctly.

Proposed resolution

Add the base path also for the services mentioned above.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇩🇪Germany jurgenhaas Gottmadingen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jurgenhaas
  • @jurgenhaas opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Status changed to Needs work over 1 year ago
  • 🇳🇴Norway eiriksm Norway

    > In tests, though, the base path is being added correctly.

    Is there any way we could come up with a failing test st least. Based on the description that sounds possible?

    Could you write up steps to reproduce on a clean install?

  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    I don't know if a failing test would be possible. What the MR does, is to set the base URL always as this:

    $baseUrl = $this->request->getSchemeAndHttpHost() . $this->request->getBasePath();
    

    The trailing $this->request->getBasePath() is missing so far. But the 2 test classes LinkcheckerLinkExtractorServiceTest and LinkcheckerRepair301Test have already defined the base path in the correct format including the trailing $this->request->getBasePath().

    In "normal" installations, that doesn't make any difference, as $this->request->getBasePath() is empty anyways. But if Drupal is installed in a sub-directory, so that you have to call the front-page as https://www.example.com/subpath, i.e. the index.php is in that subdirectory and not in the web root, then /subpath is what $this->request->getBasePath() return. To make it even more clear, the URL for node 1 would then be https://www.example.com/subpath/node/1.

    As this scenario requires a webserver setup accordingly, I don't know if something like that could be covered by our test environment.

Production build 0.71.5 2024