php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80266 parse_url silently drops port number 0
Submitted: 2020-10-21 06:38 UTC Modified: 2020-11-04 10:22 UTC
From: smiley at chillerlan dot net Assigned: cmb (profile)
Status: Closed Package: *URL Functions
PHP Version: 7.3.24, 7.4.12 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: smiley at chillerlan dot net
New email:
PHP Version: OS:

 

 [2020-10-21 06:38 UTC] smiley at chillerlan dot net
Description:
------------
In the current PHP 8 nightly Linux builds, parse_url() drops silently an invalid port number 0 and returns an array with the host part of an otherwise invalid URI.
PHP 7 on Linux & Windows, as well as PHP 8 on Windows will return false instead, which is expected.

https://github.com/chillerlan/php-httpinterface/runs/1284984428#step:10:21

https://travis-ci.org/github/chillerlan/php-httpinterface/jobs/737623526#L288

Test script:
---------------
$parsed = parse_url('//portcannotbezero.com:0');

var_dump($parsed);

https://github.com/chillerlan/php-httpinterface/commit/cefbdb1163d508f52f199abd4b958319b48012ba

Source: https://github.com/chillerlan/php-httpinterface/blob/46b563fd9ab2b92c1cf4efa3c429d6872de2eab4/src/Psr7/Uri.php#L65-L69

https://github.com/chillerlan/php-httpinterface/blob/46b563fd9ab2b92c1cf4efa3c429d6872de2eab4/tests/Psr7/UriTest.php#L144-L149

(similar to guzzle/psr7)

Expected result:
----------------
parse_url('//portcannotbezero.com:0') should return the same result "false" across all platforms.

https://github.com/chillerlan/php-httpinterface/runs/1284984456

https://travis-ci.org/github/chillerlan/php-httpinterface/jobs/737623525#L287

Actual result:
--------------
array(1) {

  'host' =>

  string(20) "portcannotbezero.com"

}

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-21 06:51 UTC] sjon@php.net
-Status: Open +Status: Not a bug
 [2020-10-21 06:51 UTC] sjon@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not a bug, for an extensive explanation see Bug #80114

https://bugs.php.net/bug.php?id=80114
 [2020-10-21 06:55 UTC] requinix@php.net
-Status: Not a bug +Status: Open -Operating System: Linux +Operating System: Windows
 [2020-10-21 06:55 UTC] requinix@php.net
@sjon: But apparently the Windows builds aren't showing this new behavior.
 [2020-10-21 07:00 UTC] smiley at chillerlan dot net
Since this was marked as "Not a bug", i'd like to point out the inconsistency across the several platforms, as well as the current behaviour in userland. The used test stems from current PSR-7 implementations where it is expected to be an invalid URI. See also: https://github.com/guzzle/psr7/blob/7858757f390bbe4b3d81762a97d6e6e786bb70ad/tests/UriTest.php#L137
 [2020-10-21 07:36 UTC] cmb@php.net
$ x64\Debug\php -v
PHP 8.0.0-dev (cli) (built: Oct 16 2020 18:46:05) ( NTS Visual C++ 2019 x64 DEBUG )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

C:\php-sdk\phpdev\vs16\x64\php-src-8.0
$ x64\Debug\php -r "var_dump(parse_url('//portcannotbezero.com:0'));"
array(1) {
  ["host"]=>
  string(20) "portcannotbezero.com"
}

IOW, I cannot reproduce.
 [2020-10-21 07:44 UTC] smiley at chillerlan dot net
@cmb: in fact, you could reproduce what the Windows build of the GH actions runner didn't. Aside, if this is now expected behaviour, why is the "port" key with a value 0 missing in the array - according to the previously linked bug, the port number 0 should be treated as valid?
 [2020-10-21 10:00 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-10-21 10:00 UTC] cmb@php.net
Firstly, this is not particularly related to PHP 8.0,
but rather affects PHP-7.3+.

> […] in fact, you could reproduce what the Windows build of the
> GH actions runner didn't.

The GH actions runner uses PHP 7.4.11 (which does not have that
bugfix) and some PHP 8.0.0-dev version (which presumably does not
have the bugfix either).

> Aside, if this is now expected behaviour, why is the "port" key
> with a value 0 missing in the array

From the commit message:

| URIs with a 0 port are generally valid, so `parse_url()` should
| recognize such URIs, but still report the port as missing.

Apparently, we should document that behavior.
 [2020-10-21 10:01 UTC] cmb@php.net
-PHP Version: 8.0.0RC2 +PHP Version: 7.3.24, 7.4.12
 [2020-10-21 12:41 UTC] smiley at chillerlan dot net
> Apparently, we should document that behavior.

Yes, that would be greatly appreciated, also a mention in UPGRADING would be helpful.

Thanks for clearing this up and thank you for your time! I think this can be closed then. Cheers!
 [2020-10-27 11:12 UTC] nikic@php.net
| URIs with a 0 port are generally valid, so `parse_url()` should
| recognize such URIs, but still report the port as missing.

I do wonder whether that's the right behavior. It would make more sense to include the zero port in the output to me.
 [2020-10-27 12:50 UTC] cmb@php.net
> It would make more sense to include the zero port in the output
> to me.

After further consideration, I have to agree.
 [2020-10-30 16:39 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-11-04 10:22 UTC] cmb@php.net
-Summary: parse_url silently drops invalid port number, inconsistent across platforms +Summary: parse_url silently drops port number 0 -Type: Documentation Problem +Type: Bug
 [2020-11-04 10:57 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #80266: parse_url silently drops port number 0
On GitHub:  https://github.com/php/php-src/pull/6399
Patch:      https://github.com/php/php-src/pull/6399.patch
 [2020-11-04 13:59 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2cab085bb37a6980b8f23a4b3c31b813ac67cda0
Log: Fix #80266: parse_url silently drops port number 0
 [2020-11-04 13:59 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC