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

Url-escaped slash prefixed to normalised path #67

Closed
mattattui opened this issue Mar 15, 2016 · 5 comments
Closed

Url-escaped slash prefixed to normalised path #67

mattattui opened this issue Mar 15, 2016 · 5 comments
Labels
bug Something isn't working

Comments

@mattattui
Copy link

Bit of an odd one:

<?php
require __DIR__.'/vendor/autoload.php';

use League\Uri\Modifiers\Normalize;
use League\Uri\Schemes\Http as HttpUri;

$rawUrl = 'HtTp://vonNN.com/ipsam-nulla-adipisci-laboriosam-dignissimos-accusamus-eum-voluptatem';
$uriNormalizer = new Normalize();
$uri = (string) $uriNormalizer(HttpUri::createFromString($rawUrl));

assert($uri === 'http://vonnn.com/ipsam-nulla-adipisci-laboriosam-dignissimos-accusamus-eum-voluptatem');
echo $uri . PHP_EOL;

Currently outputs:

Warning: assert(): assert($uri === 'http://vonnn.com/ipsam-nulla-adipisci-laboriosam-dignissimos-accusamus-eum-voluptatem') failed in /var/www/app/erk.php on line 11
http://vonnn.com/%2Fipsam-nulla-adipisci-laboriosam-dignissimos-accusamus-eum-voluptatem

An extra %2F has snuck in right after the host and initial slash.

@mattattui
Copy link
Author

(Sorry, I'd write a proper test-case and dig into the code and offer a PR but I'm really busy 😿)

@nyamsprod nyamsprod added the bug Something isn't working label Mar 16, 2016
@nyamsprod
Copy link
Member

I have found the culprit 👍

https://github.com/thephpleague/uri/blob/master/src/Types/ImmutableComponentTrait.php#L109

the bug appears because depending on context the static::$characters_set compile the wrong value. This method was added in 4.1 to improve code speed. Seems I'll have to look into it more closely or revert to the previous behavior.

nyamsprod referenced this issue in thephpleague/uri Mar 16, 2016
nyamsprod referenced this issue in thephpleague/uri Mar 16, 2016
nyamsprod referenced this issue in thephpleague/uri Mar 16, 2016
nyamsprod referenced this issue in thephpleague/uri Mar 17, 2016
- remove buggy internal ImmutableComponentTrait::getReservedRegex method
- remove unused internal static variable $characters_set_encoded
- remove static variable $characters_set

To fix the issue and keep the speed improvement, all Path related
component classes are now encoded/decoded using the same mechanism/code.

- PathTrait::encodePath and PathTrait::decodePath are added.
- internal static variable representing the regular expression of the
path reserved characters is used
nyamsprod referenced this issue in thephpleague/uri Mar 17, 2016
- remove buggy internal ImmutableComponentTrait::getReservedRegex method
- remove unused internal static variable $characters_set_encoded
- remove static variable $characters_set

To fix the issue and keep the speed improvement, all Path related
component classes are now encoded/decoded using the same mechanism/code.

- PathTrait::encodePath and PathTrait::decodePath are added.
- internal static variable representing the regular expression of the
path reserved characters is used
nyamsprod referenced this issue in thephpleague/uri Mar 18, 2016
@nyamsprod
Copy link
Member

The bug fix is now merge on the master branch. I'll close this issue when the new release will be tagged

@mattattui
Copy link
Author

Fantastic, thank you!

@nyamsprod
Copy link
Member

version 4.1.1 is released with the bug fix

@nyamsprod nyamsprod transferred this issue from thephpleague/uri Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants