User tests: Successful: Unsuccessful:
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.
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.
This screenshot shows that the content of the Location header is an array, not a string. Which is the reason for the error.

The problem was found only when using the CURLOPT_FOLLOWLOCATION = false parameter. In this case, Joomla executes the redirect url request on its own.
Change a $redirect_uri = new Uri($response->headers['Location']); to $redirect_uri = new Uri($response->headers['Location'][0]);
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.
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>';parse_url(): Argument #1 ($url) must be of type string, array givenor 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
An error parse_url(): Argument #1 ($url) must be of type string, array given in ROOT\libraries\vendor\joomla\uri\src\UriHelper.php:38
Error has gone
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
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
I have tested. Work ok
| Status | Pending | ⇒ | Ready to Commit |
RTC
| Labels |
Added:
PR-5.1-dev
|
||
@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.
| Title |
|
||||||
| Labels |
Added:
RTC
bug
|
||
| 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 |
Thank you @sergeytolkachyov and also for testing @gug2 @progreccor
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.