Problem/Motivation

In CommentTokensHooks::tokens(), the homepage token replacement calls UrlHelper::stripDangerousProtocols($comment->getHomepage()) unconditionally. However, Comment::getHomepage() returns NULL when the homepage field has no value (it reads $this->get('homepage')->value which is NULL for an empty URI field).

UrlHelper::stripDangerousProtocols() expects a string parameter. Passing NULL causes a deprecation notice (Passing null to parameter #1 ($haystack) of type string is deprecated from the internal strpos() call)

This affects any token replacement involving [comment:homepage] when the comment author did not provide a homepage URL, which is the common case for authenticated users.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3578193

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

jurgenhaas created an issue. See original summary.

jurgenhaas’s picture

Status: Active » Needs review

I've fixed the test by adding another entry to the phpstan baseline following the pattern of around 45 others doing the same.

smustgrave’s picture

Status: Needs review » Needs work

1 small comment on the MR.

jurgenhaas’s picture

Status: Needs work » Needs review

Combined the tests.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative

Thanks!

alexpott’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 65bd47cd354 to main and ece978bbaab to 11.x and 0c0189c2c1a to 11.3.x. Thanks!

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.

  • alexpott committed 0c0189c2 on 11.3.x
    fix: #3578193 CommentTokensHooks passes NULL to UrlHelper::...

  • alexpott committed ece978bb on 11.x
    fix: #3578193 CommentTokensHooks passes NULL to UrlHelper::...

  • alexpott committed 65bd47cd on main
    fix: #3578193 CommentTokensHooks passes NULL to UrlHelper::...

Status: Fixed » Closed (fixed)

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