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
Issue fork linkchecker-3607990
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
Comment #2
groendijk commentedComment #3
joelpittetMoving to dev branch, ran into this as well, as a result of updated security releases of guzzle I assume. Thanks for reporting this!
Comment #4
joelpittetGoing to drop in a quick fix style MR on this in a moment.
Comment #6
joelpittetAI helped draft, then I got it to cast it to a string before
trim()because didn't want theis_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.Comment #7
groendijk commentedThank 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..
Comment #8
joelpittetBumping this to a normal bug:
guzzlehttp/psr72.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 uncaughtMalformedUriExceptionand aborts the entire link check run. Not new functionality but rather a regression that breaks link checking on up-to-date sites.Comment #9
groendijk commentedJust tested the trim functionality. Works good. Update hook updates the urls with extra whitespace. Guess this can be released.
Comment #10
joelpittetThanks @groendijk! I would say it's good to merge too
Comment #12
codebymikey commentedThis 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.
Comment #14
joelpittet@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!