Skip to content

Url::ensureScheme does not work in some cases #17191

Closed
@SamMousa

Description

@SamMousa

What steps will reproduce the problem?

Url::ensureScheme('google.nl/test?param=https://someother.url/', 'https');

What is the expected result?

https://google.nl/test?param=https://someother.url/

What do you get instead?

google.nl/test?param=https://someother.url/

Additional info

This happens because this check is done:

if (($pos = strpos($url, '://')) !== false) {
            if ($scheme === '') {
                $url = substr($url, $pos + 1);
            } else {
                $url = $scheme . substr($url, $pos);
            }
        }

We should use parse_url to get the correct parts instead of using strpos.
If parse_url is not available then we could at least split the string by ? to ensure we ignore the query part.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions