LanguageNegotiationUrl::processOutbound() modifies absolute option to TRUE which implicitly changes behavior of Url::setAbsolute(FALSE)->toString()

Created on 18 June 2021, about 3 years ago
Updated 10 December 2023, 7 months ago

Problem/Motivation

LanguageNegotiationUrl::processOutbound() includes the manipulation of the 'absolute' option:

<?php
        // Ask for an absolute URL with our modified base URL.
        $options['absolute'] = TRUE;
        $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()];
        // ...
?>

Leading to the situation that if you want to generate a Url string, e.g. from an entity like this:

<?php
$entity->toUrl()->setAbsolute(FALSE)->toString();
?>

... you'll end up having an absolute Url string regardless your previously set option.
This can be a huge problem, as it leads to unexpected (and most probably untested) behavior where errors might not be noticed immediately, but after some period of time when things might be just too late to fix them.

Steps to reproduce

I'll try to find time to be more concise about how to reproduce this problem. Basically you need a multilingual site with domains configured accordingly, then having some part in your code that wants to have a relative Url.

Proposed resolution

Maybe it would help to fail hard by throwing an exception, when the 'absolute' option was explicitly set to FALSE before.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated about 21 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡©πŸ‡ͺGermany mxh Offenburg

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024