Setting 300 Code as Default Redirect causes Fatal error (300 not supported by symfony http-foundation)

Created on 2 November 2017, about 7 years ago
Updated 5 October 2023, about 1 year ago

This is not a bug per se in Redirect, but either a bug or a limitation of http-foundation in symfony.

http foundation used to use an isRedirection function to validate redirect

?>
    /**
     * Is the response a redirect?
     *
     * @return bool
     *
     * @final since version 3.2
     */
    public function isRedirection()
    {
        return $this->statusCode >= 300 && $this->statusCode < 400;
    }

but now they use an isRedirect function that leaves out code 300

    /**
     * Is the response a redirect of some form?
     *
     * @param string $location
     *
     * @return bool
     *
     * @final since version 3.2
     */
    public function isRedirect($location = null)
    {
        return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
    }

Which means that if you have the option " Enforce clean and canonical URLs." and default redirect Status 300 set up in the redirect module, and you visit an url triggering a redirect (for instance ending in a slash), you will get a PHP fatal error and:
InvalidArgumentException The HTTP status code is not a redirect.

I'm opening this issue to inform drupal folks, while looking into a pull request for the http-foundation library to ask for explanation about 300 not being supported. In the meantime, maybe we should disable that combination of options? Or maybe make 302 the default code at least so folks checking the checkbox Enforce clean and canonical URLs don't get a broken site by default?

Update:here is the pull request to support code 300 in http-foundation.

📌 Task
Status

Needs work

Version

1.0

Component

Code

Created by

🇩🇪Germany yareckon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

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.71.5 2024