psr7 icon indicating copy to clipboard operation
psr7 copied to clipboard

`Uri::__toString()` can yield malformed URIs

Open dtdesign opened this issue 2 years ago • 5 comments

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.

dtdesign avatar Oct 17 '23 11:10 dtdesign

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.

GrahamCampbell avatar Nov 18 '23 21:11 GrahamCampbell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 01 '25 00:02 stale[bot]

Not stale.

GrahamCampbell avatar Feb 01 '25 00:02 GrahamCampbell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 26 '25 22:06 stale[bot]

Not stale.

GrahamCampbell avatar Jun 27 '25 07:06 GrahamCampbell