-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[5.1] Change redirect url (from headers['Location']) from array to string in CurlTransport #42769
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
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
requestmethod executes a request to the specified url of thestringtype. If the response code indicates a redirect, then the redirect url is obtained from theLocationheader. After that, another request is executed with a new url.The redirect url is an instance of the
Uriclass. During the operation of this class, theUrlHelperclass 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 theUriHelperclass 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 = falseparameter. 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.phpfile.parse_url(): Argument #1 ($url) must be of type string, array givenor in the file
libraries/src/Http/Transport/CurlTransport.phpfind 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 givenin 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