Visitar URL original
Uri\Rfc3986\Uri::toString() doesn't drop an empty port · Issue #23965 · php/php-src · GitHub
Skip to content

Uri\Rfc3986\Uri::toString() doesn't drop an empty port #23965

Description

@kamil-tekiela

Description

The following code:

<?php

require 'vendor/autoload.php';

$uri = new Uri\Rfc3986\Uri('https://example.com:');
var_dump($uri->getPort(), $uri->toRawString(), $uri->toString());

Resulted in this output:

NULL
string(20) "https://example.com:"
string(20) "https://example.com:"

But I expected this output instead:

NULL
string(20) "https://example.com:"
string(19) "https://example.com"

PHP Version

8.5.4

Operating System

No response

Activity

  1. iluuu1994 commented on Sep 28, 2026

    @iluuu1994
    Member
  2. kamil-tekiela commented on Sep 28, 2026

    @kamil-tekiela
    MemberAuthor

    FYI Reposted from thephpleague/uri-src#215 (comment)

    I have opened several bug reports for polyfill, but you may want to check whether some of them aren't PHP bugs. https://github.com/thephpleague/uri-src/issues?q=is%3Aissue%20author%3Akamil-tekiela

  3. self-assigned this
    on Sep 28, 2026
  4. kocsismate commented on Sep 28, 2026

    @kocsismate
    Member

    The normalization in question is mentioned in RFC 3986 (with a SHOULD though):

    Likewise, an explicit ":port", for which the port is empty or the default for the scheme, is equivalent to one where the port and its ":" delimiter are elided and thus should be removed by scheme-based normalization.

    Currently, uriparser doesn't implement this normalization yet:

    /* Is there a port even? */

    I'll try to implement it sometime soon (although uriparser reviews take a lot of time nowadays).

  5. kocsismate commented on Sep 28, 2026

    @kocsismate
    Member

    P.S. this normalization option is mentioned wrt scheme-based normalization (section 6.2.1 in the RFC) which - by itself - is out of scope for a library implementing the generic URI syntax (uriparser/uriparser#173).

    However, I'd argue that normalizing "https://example.com:" to "https://example.com" falls in the scheme-based normalization category, so maybe it's still worth a try to implement in uriparser, especially because the RFC references this case in another section:

    URI producers and normalizers should omit the ":" delimiter that separates host from port if the port component is empty. Some schemes do not allow the userinfo and/or port subcomponents.

  6. TimWolla commented on Sep 28, 2026

    @TimWolla
    Member

    3.2.3 states:

    URI producers AND normalizers should omit the port component and its ":" delimiter if port is empty or if its value would be the same as that of THE scheme's default.

    This I would expect normalization to happen in uriparser.

  7. TimWolla commented on Sep 28, 2026

    @TimWolla
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions