Problem/Motivation

Sometimes users can write wrong links. Links with an empty space in it eg:
<a href="https://www.drupal.org ">https://www.drupal.org </a>

Linkchecker adds the url with the space to check. GuzzleHttp doesn't like the extra space and gives a warning:
GuzzleHttp\Psr7\Exception\MalformedUriException: Invalid host: "www.drupal.org " in GuzzleHttp\Psr7\Uri->__construct() (line 76 of /data/releases/1337/vendor/guzzlehttp/psr7/src/Uri.php)

Link does work in the frontend, but linkchecker quits.

Steps to reproduce

Add a link with space ' '
Let Linkchecker run

Proposed resolution

Maybe trim the links? Could be in the LinkCheckerService.php or ...

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

groendijk created an issue. See original summary.

groendijk’s picture

Title: Trim urls » Trim links
joelpittet’s picture

Version: 2.1.0 » 2.1.x-dev

Moving to dev branch, ran into this as well, as a result of updated security releases of guzzle I assume. Thanks for reporting this!

joelpittet’s picture

Status: Active » Needs review

Going to drop in a quick fix style MR on this in a moment.

joelpittet’s picture

AI helped draft, then I got it to cast it to a string before trim() because didn't want the is_string() checks. Also in the test I just light touched to remove some <10.2 checks that weren't needed and set the docblock param/var descriptions in favour of type hints. It's minor priority, which I agree, so leaving that.

groendijk’s picture

Thank you for looking at it! Did a small review on it. Code works but maybe there's a small improvement. Comment in MR.
Oh wow.. comment from MR is here too..

joelpittet’s picture

Title: Trim links » Trim whitespace from link URLs to prevent MalformedUriException halting link checks
Category: Feature request » Bug report
Priority: Minor » Normal

Bumping this to a normal bug: guzzlehttp/psr7 2.10.2 (GHSA-hq7v-mx3g-29hw) started rejecting whitespace in URI hosts as part of a security fix, so a single link with a stray space now throws an uncaught MalformedUriException and aborts the entire link check run. Not new functionality but rather a regression that breaks link checking on up-to-date sites.

groendijk’s picture

Status: Needs review » Reviewed & tested by the community

Just tested the trim functionality. Works good. Update hook updates the urls with extra whitespace. Guess this can be released.

joelpittet’s picture

Thanks @groendijk! I would say it's good to merge too

  • joelpittet committed 4d5c8a23 on 2.1.x
    fix: #3607990 Trim whitespace from link URLs to prevent...
codebymikey’s picture

Status: Reviewed & tested by the community » Fixed

This doesn't address the scenario where the space is within the host.

But there's a separate issue for that in #3604202: Invalid href attribute value in WYSIWYG field causes fatal error during link checking, so it'll be handled there.

Flagging as fixed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joelpittet’s picture

@codebymikey thanks for pointing at the other issue and marking this as fixed (it was late, I just went to bed).

@groendijk thanks for working with me on this!

  • joelpittet committed 457d1085 on 3.0.x
    fix: #3607990 Trim whitespace from link URLs to prevent...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.