RTC bug PR-5.1-dev Pending

User tests: Successful: Unsuccessful:

avatar sergeytolkachyov
sergeytolkachyov
7 Feb 2024

The problem was discovered when using HTTP Factory for an external request to the server that performs redirection. The request method executes a request to the specified url of the string type. If the response code indicates a redirect, then the redirect url is obtained from the Location header. After that, another request is executed with a new url.

image

The redirect url is an instance of the Uri class. During the operation of this class, the UrlHelper class is called, in which the url is parsed. When making the first request, the url type is a string. However, in the case of redirection, the url is an array with one element, since $response->headers['Location'] is passed immediately as an argument. Therefore, when trying to make a second request for a new URl, the error parse_url() occurs: Argument #1 ($url) must be of type string, array given in the UriHelper class line 38.

image

This screenshot shows that the content of the Location header is an array, not a string. Which is the reason for the error.
image

The problem was found only when using the CURLOPT_FOLLOWLOCATION = false parameter. In this case, Joomla executes the redirect url request on its own.

Summary of Changes

Change a $redirect_uri = new Uri($response->headers['Location']); to $redirect_uri = new Uri($response->headers['Location'][0]);

Testing Instructions

It may not be the most correct, but the fastest way to check the result of this change is to run the query directly from the template index.php file.

  1. Open it index.php Your frontend template
  2. Add the following code to it
use Joomla\CMS\Http\HttpFactory;

$options = new Registry();
$options->set(
	'transport.curl',
	[
		CURLOPT_FOLLOWLOCATION   => false, 
	]
);

$http = (new HttpFactory)->getHttp($options, ['curl', 'stream']);

$url = 'enter here any URL with redirect ';

$response = $http->get($url);
echo '<pre>';
print_r($response->body);
echo '</pre>';
  1. Run the request (refresh the page) and you will see an error parse_url(): Argument #1 ($url) must be of type string, array given
  2. Apply this PR (download the build and update Joomla 5.0.2)

image

or in the file libraries/src/Http/Transport/CurlTransport.php find the line $redirect_uri = new Uri($response->headers['Location']) and replace it to $redirect_uri = new Uri($response->headers['Location'][0]);
5. Run the request again (refresh the page again)
6. Error has gone

Actual result BEFORE applying this Pull Request

An error parse_url(): Argument #1 ($url) must be of type string, array given in ROOT\libraries\vendor\joomla\uri\src\UriHelper.php:38

image

Expected result AFTER applying this Pull Request

Error has gone

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar sergeytolkachyov sergeytolkachyov - open - 7 Feb 2024
avatar sergeytolkachyov sergeytolkachyov - change - 7 Feb 2024
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Feb 2024
Category Libraries
avatar sergeytolkachyov sergeytolkachyov - change - 7 Feb 2024
The description was changed
avatar sergeytolkachyov sergeytolkachyov - edited - 7 Feb 2024
avatar sergeytolkachyov sergeytolkachyov - change - 7 Feb 2024
The description was changed
avatar sergeytolkachyov sergeytolkachyov - edited - 7 Feb 2024
avatar sergeytolkachyov sergeytolkachyov - change - 7 Feb 2024
The description was changed
avatar sergeytolkachyov sergeytolkachyov - edited - 7 Feb 2024
avatar gug2 gug2 - test_item - 8 Feb 2024 - Tested successfully
avatar gug2
gug2 - comment - 8 Feb 2024

I have tested this item ✅ successfully on d1032db

Tested successfully


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42769.

avatar progreccor
progreccor - comment - 12 Feb 2024

I have tested. Work ok

avatar Quy Quy - alter_testresult - 12 Feb 2024 - progreccor: Tested successfully
avatar Quy Quy - change - 12 Feb 2024
Status Pending Ready to Commit
avatar Quy
Quy - comment - 12 Feb 2024

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42769.

avatar Quy Quy - change - 12 Feb 2024
Labels Added: PR-5.1-dev
avatar sergeytolkachyov
sergeytolkachyov - comment - 21 Feb 2024
avatar sergeytolkachyov
sergeytolkachyov - comment - 24 Feb 2024

@Quy Joomla 5.1.0 Alpha 4 has been released at 20 February 2024. This pr was RTC 2 weeks ago but stll not merged.

avatar HLeithner
HLeithner - comment - 2 Mar 2024

@Quy Joomla 5.1.0 Alpha 4 has been released at 20 February 2024. This pr was RTC 2 weeks ago but stll not merged.

RTC doesn't mean that it get automatically merged, it in only means that the pr has 2 tests. But still a maintainer has to check the pr and consider side effects. So it could take some time till a maintainer has time to validate the issue and check if the fix is the correct way.

avatar HLeithner HLeithner - edited - 24 Apr 2024
avatar HLeithner HLeithner - change - 24 Apr 2024
Title
Change redirect url (from headers['Location']) from array to string in CurlTransport
[5.1] Change redirect url (from headers['Location']) from array to string in CurlTransport
avatar LadySolveig LadySolveig - change - 20 May 2024
Labels Added: RTC bug
avatar LadySolveig LadySolveig - change - 20 May 2024
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2024-05-20 11:56:28
Closed_By LadySolveig
avatar LadySolveig LadySolveig - close - 20 May 2024
avatar LadySolveig LadySolveig - merge - 20 May 2024
avatar LadySolveig
LadySolveig - comment - 20 May 2024

Thank you @sergeytolkachyov and also for testing @gug2 @progreccor

Add a Comment

Login with GitHub to post a comment