php / php-src

The PHP Interpreter
https://www.php.net
Other
38.19k stars 7.75k forks source link

Colon in url path is not parsed by `parse_url` #12703

Open vdauchy opened 12 months ago

vdauchy commented 12 months ago

Description

parse_url() return false on absolute path containing : and no query string.

The following code:

<?php
var_dump(parse_url('/page:1?foo=bar'));  // Working example of parsing.

var_dump(parse_url('/page:1'));
var_dump(parse_url('/page:1', \PHP_URL_SCHEME));

Resulted in this output:

array(2) {
  ["path"]=>
  string(7) "/page:1"
  ["query"]=>
  string(7) "foo=bar"
}

bool(false)
bool(false)

But I expected this output instead:

array(2) {
  ["path"]=>
  string(7) "/page:1"
  ["query"]=>
  string(7) "foo=bar"
}

array(1) {
  ["path"]=>
  string(7) "/page:1"
}
NULL

This issue is opened following discussion on Symfony DomCrawler: https://github.com/symfony/symfony/issues/52628

PHP Version

8.1.12

Operating System

No response

nicolas-grekas commented 2 months ago

We should still fix this case IMHO. The engine currently fails to parse valid URLs. I implemented a workaround in https://github.com/symfony/symfony/pull/58218 but this is not pretty :)