Problem/Motivation

\Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession can cause deprecations on PHP 8.1 when there is no query string.

It does parse_str($request->getQueryString(), $query); which will trigger a deprecation if $request->getQueryString() returns a NULL.

Steps to reproduce

See https://3v4l.org/GeMuL
Run \Drupal\FunctionalTests\Routing\RouteCachingNonPathLanguageNegotiationTest

Proposed resolution

Don't pass a NULL to parse_str

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new962 bytes

In the meta issue I did:
parse_str($request->getQueryString() ?? '', $query);
But on re-examining the code this is unnecessarily complex - calling $request->getQueryString() parses and then builds the query string again! Which is completely unnecessary - elsewhere in core we do $request->query->all() and I can't think of a reason why we shouldn't here.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

without fix test fails

Exception : Deprecated function: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated
Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession->getLanguageSwitchLinks()() (Line: 132)

after patch there's still unrelated

  36x: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
    36x in RouteCachingNonPathLanguageNegotiationTest::testAliases from Drupal\FunctionalTests\Routing
andypost’s picture

The only difference I bet is sorting - \Symfony\Component\HttpFoundation\Request::normalizeQueryString() sort keys

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed c9bcb2c and pushed to 9.3.x. Thanks!

  • larowlan committed c9bcb2c on 9.3.x
    Issue #3240905 by alexpott: \Drupal\language\Plugin\LanguageNegotiation\...

Status: Fixed » Closed (fixed)

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

mozh92’s picture

StatusFileSize
new772 bytes

Hello, I found deprecated code in file LanguageNegotiationContentEntity.php yet

andypost’s picture

@mozh92 please file new issue instead of adding patches to closed one