Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

parse_url() returns false on colon(:) followed by number inside path #17862

Closed
RV7PR opened this issue Feb 19, 2025 · 2 comments
Closed

parse_url() returns false on colon(:) followed by number inside path #17862

RV7PR opened this issue Feb 19, 2025 · 2 comments

Comments

@RV7PR
Copy link

RV7PR commented Feb 19, 2025

Description

The following code:

<?php
print_r(parse_url('https://test.com/a/b/c:354/'));
print_r(parse_url('test.com/a/b/c:354/'));
print_r(parse_url('/a/b/c:354/'));

Resulted in this output:

Array
(
    [scheme] => https
    [host] => test.com
    [path] => /a/b/c:354/
)
Array
(
    [host] => test.com
    [port] => 354
    [path] => /a/b/c:354/
)

But I expected this output instead:

Array
(
    [scheme] => https
    [host] => test.com
    [path] => /a/b/c:354/
)
Array
(
    [host] => test.com
    [path] => /a/b/c:354/
)
Array
(
    [path] => /a/b/c:354/
)

PHP Version

PHP 8.4.4

Operating System

No response

@cmb69
Copy link
Member

cmb69 commented Feb 19, 2025

Yeah: https://3v4l.org/hLssX

This is a know problem; IIRC, there is a shortcut in the "parser" to find the port, and that can screw up proper handling of relative URLs with colon-portlike in the path.

That is basically documented:

Partial and invalid URLs are also accepted, parse_url() tries its best to parse them correctly.

"Its best" is just not good enough here.

I don't think it makes sense to try to fix that (might break too many other edge cases), and since there is an RFC under discussion which would introduce proper URL/URI parsers anyway, it might make even less sense to fiddle with parse_url().

@iluuu1994
Copy link
Member

This is pretty much an exact duplicate of #7890, so should probably be closed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants