Skip to content
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

Uri::__toString() can yield malformed URIs #583

Open
dtdesign opened this issue Oct 17, 2023 · 1 comment
Open

Uri::__toString() can yield malformed URIs #583

dtdesign opened this issue Oct 17, 2023 · 1 comment

Comments

@dtdesign
Copy link

dtdesign commented Oct 17, 2023

PHP version: 8.2.11
guzzlehttp/psr7: 2.6.1

Description
The Uri class is able to parse malformed URIs but this results in Uri::__toString() generating a malformed URI. Attempting to pass that URI back into Uri will yield a MalformedUriException.

How to reproduce

$value = 'http://invalid:%20https://example.com';
$uri = new \GuzzleHttp\Psr7\Uri($value);
$uri2 = new \GuzzleHttp\Psr7\Uri($uri->__toString()); // Exception is thrown here.

Line 3 throws a GuzzleHttp\Psr7\Exception\MalformedUriException with the following error message:

Unable to parse URI: http://invalid:%20https//example.com

Notice how the colon after the https was stripped.

@GrahamCampbell
Copy link
Member

Thanks for the report. I am a little hesitent to change the behaviour here in 1.x or 2.x, but I am planning for 3.x to make some breaking changes to "fix" some spec compatibility issues, and this could be one such fix, if we can agree on a correct behaviour over on the php-http/psr7-integration-tests repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants