-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.1] Change redirect url (from headers['Location']) from array to string in CurlTransport #42769
Conversation
I have tested this item ✅ successfully on d1032db This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42769. |
I have tested. Work ok |
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42769. |
@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. |
Thank you @sergeytolkachyov and also for testing @gug2 @progreccor |
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 thestring
type. If the response code indicates a redirect, then the redirect url is obtained from theLocation
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, theUrlHelper
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 theUriHelper
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.
![image](https://private-user-images.githubusercontent.com/6236403/302923015-a57d9359-e4c3-42ef-bfd2-6dbbac6124e7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMwNjE3NTgsIm5iZiI6MTcyMzA2MTQ1OCwicGF0aCI6Ii82MjM2NDAzLzMwMjkyMzAxNS1hNTdkOTM1OS1lNGMzLTQyZWYtYmZkMi02ZGJiYWM2MTI0ZTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MDdUMjAxMDU4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTYwNTdhMmZhOGRmZjQwNTAzZDgyODYzMTk1YTI3MDI1Yjk2MzdjOTdlMjg1ZWM4NWFmN2NlMzI0M2Y3ZDRhMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.SSqxcH4-r2mOd_reWUpitPqTqnZeTuAqqhVU7vgQfwM)
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.parse_url(): Argument #1 ($url) must be of type string, array given
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:38Expected 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