diff --git a/libraries/joomla/application/web.php b/libraries/joomla/application/web.php index 2852ad643075a..c32bf62e2ec69 100644 --- a/libraries/joomla/application/web.php +++ b/libraries/joomla/application/web.php @@ -546,9 +546,11 @@ public function redirect($url, $status = 303) $status = $status ? 301 : 303; } - if (!is_int($status) && !isset($this->responseMap[$status])) + // Now check if we have an integer status code that maps to a valid redirect. If we don't then set a 303 + // @deprecated 4.0 From 4.0 if no valid status code is given a InvalidArgumentException will be thrown + if (!is_int($status) || is_int($status) && !isset($this->responseMap[$status])) { - throw new \InvalidArgumentException('You have not supplied a valid HTTP 1.1 status code'); + $status = 303; } // All other cases use the more efficient HTTP header for redirection. diff --git a/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php b/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php index 3967c8b1480a1..0f719fb6bf899 100644 --- a/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php +++ b/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php @@ -451,6 +451,51 @@ public function testRedirectLegacy() ); } + /** + * Tests the JApplicationCms::redirect method. + * + * @return void + * + * @since 3.2 + */ + public function testRedirectLegacyWithEmptyMessageAndEmptyStatus() + { + $base = 'http://mydomain.com/'; + $url = 'index.php'; + + // Inject the client information. + TestReflection::setValue( + $this->class, + 'client', + (object) array( + 'engine' => JApplicationWebClient::GECKO, + ) + ); + + // Inject the internal configuration. + $config = new Registry; + $config->set('uri.base.full', $base); + + TestReflection::setValue($this->class, 'config', $config); + + $this->class->redirect($url, '', 'message'); + + // The message isn't enqueued as it's an empty string + $this->assertEmpty( + $this->class->getMessageQueue() + ); + + // The redirect gives a 303 error code + $this->assertEquals( + array( + array('HTTP/1.1 303 See other', true, null), + array('Location: ' . $base . $url, true, null), + array('Content-Type: text/html; charset=utf-8', true, null), + ), + $this->class->headers + ); + } + /** * Tests the JApplicationCms::redirect method with headers already sent. *