Bug 2584089

Summary: python-bleach fails to build with Python 3.16: ValueError: Port out of range 0-65535
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-bleachAssignee: Tom.Rix
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: epel-packagers-sig, igor.raits, ksurma, mhroncok, romain.geissler, Tom.Rix
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2567340    

Description Karolina Surma 2026-11-25 11:44:09 UTC
python-bleach fails to build with Python 3.16.0a2.

____________________ test_urlparse[http://f: /c-expected19] ____________________

uri = 'http://f: /c'
expected = ParseResult(scheme='http', netloc='f: ', path='/c', params='', query='', fragment='')

    @pytest.mark.parametrize(
        "uri, expected",
        [
            ("", ParseResult()),
            ("http://example\t.\norg", ParseResult(scheme="http", netloc="example.org")),
            (
                "http://user:pass@foo:21/bar;par?b#c",
                ParseResult(
                    scheme="http",
                    netloc="user:pass@foo:21",
                    path="/bar",
                    params="par",
                    query="b",
                    fragment="c",
                ),
            ),
            ("https://test:@test", ParseResult(scheme="https", netloc="test:@test")),
            ("https://:@test", ParseResult(scheme="https", netloc=":@test")),
            (
                "non-special://test:@test/x",
                ParseResult(scheme="non-special", netloc="test:@test", path="/x"),
            ),
            (
                "non-special://:@test/x",
                ParseResult(scheme="non-special", netloc=":@test", path="/x"),
            ),
            ("http:foo.com", ParseResult(scheme="http", path="foo.com")),
            # NOTE(willkg): The wpt tests set the scheme to http becaue that's what
            # the base url is. Since our parser is not using a baseurl, it sets the
            # scheme to "". Further, our parser includes spaces at the beginning,
            # but I don't see that as being problematic.
            ("\t   :foo.com   \n", ParseResult(path=":foo.com   ")),
            # NOTE(willkg): The wpt tests set the path to "/foo/foo.com" because
            # the base url is at "/foo"
            (" foo.com  ", ParseResult(path="foo.com  ")),
            ("a:\t foo.com", ParseResult(scheme="a", path=" foo.com")),
            (
                "http://f:21/ b ? d # e ",
                ParseResult(
                    scheme="http", netloc="f:21", path="/ b ", query=" d ", fragment=" e "
                ),
            ),
            (
                "lolscheme:x x#x x",
                ParseResult(scheme="lolscheme", path="x x", fragment="x x"),
            ),
            ("http://f:/c", ParseResult(scheme="http", netloc="f:", path="/c")),
            ("http://f:0/c", ParseResult(scheme="http", netloc="f:0", path="/c")),
            # NOTE(willkg): The wpt tests normalize the 0000000000000 to 0 so the
            # netloc should be "f:0".
            (
                "http://f:00000000000000/c",
                ParseResult(scheme="http", netloc="f:00000000000000", path="/c"),
            ),
            # NOTE(willkg): The wpt tests drop the 0000000000000000000 altogether
            # so the netloc should be "f".
            (
                "http://f:00000000000000000000080/c",
                ParseResult(scheme="http", netloc="f:00000000000000000000080", path="/c"),
            ),
            # This is an invalid ipv6 url
            ("http://2001::1]", ValueError),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f:b/c", ParseResult(scheme="http", netloc="f:b", path="/c")),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f: /c", ParseResult(scheme="http", netloc="f: ", path="/c")),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f:999999/c", ParseResult(scheme="http", netloc="f:999999", path="/c")),
        ],
    )
    def test_urlparse(uri, expected):
        if inspect.isclass(expected) and issubclass(expected, BaseException):
            with pytest.raises(expected):
                urlparse(uri)
    
        else:
>           parsed = urlparse(uri)
                     ^^^^^^^^^^^^^

tests/test_parse_shim.py:103: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.16/urllib/parse.py:486: in urlparse
    scheme, netloc, url, params, query, fragment = _urlparse(url, scheme, allow_fragments)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib64/python3.16/urllib/parse.py:499: in _urlparse
    scheme, netloc, url, query, fragment = _urlsplit(url, scheme, allow_fragments)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib64/python3.16/urllib/parse.py:646: in _urlsplit
    _checknetloc(netloc)
/usr/lib64/python3.16/urllib/parse.py:547: in _checknetloc
    _validate_port(port)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

port = ' '

    def _validate_port(port):
        if port.isdigit() and port.isascii():
            port = int(port)
        else:
>           raise ValueError(f"Port could not be cast to integer value as {port!r}")
E           ValueError: Port could not be cast to integer value as ' '

/usr/lib64/python3.16/urllib/parse.py:166: ValueError
_________________ test_urlparse[http://f:999999/c-expected20] __________________

uri = 'http://f:999999/c'
expected = ParseResult(scheme='http', netloc='f:999999', path='/c', params='', query='', fragment='')

    @pytest.mark.parametrize(
        "uri, expected",
        [
            ("", ParseResult()),
            ("http://example\t.\norg", ParseResult(scheme="http", netloc="example.org")),
            (
                "http://user:pass@foo:21/bar;par?b#c",
                ParseResult(
                    scheme="http",
                    netloc="user:pass@foo:21",
                    path="/bar",
                    params="par",
                    query="b",
                    fragment="c",
                ),
            ),
            ("https://test:@test", ParseResult(scheme="https", netloc="test:@test")),
            ("https://:@test", ParseResult(scheme="https", netloc=":@test")),
            (
                "non-special://test:@test/x",
                ParseResult(scheme="non-special", netloc="test:@test", path="/x"),
            ),
            (
                "non-special://:@test/x",
                ParseResult(scheme="non-special", netloc=":@test", path="/x"),
            ),
            ("http:foo.com", ParseResult(scheme="http", path="foo.com")),
            # NOTE(willkg): The wpt tests set the scheme to http becaue that's what
            # the base url is. Since our parser is not using a baseurl, it sets the
            # scheme to "". Further, our parser includes spaces at the beginning,
            # but I don't see that as being problematic.
            ("\t   :foo.com   \n", ParseResult(path=":foo.com   ")),
            # NOTE(willkg): The wpt tests set the path to "/foo/foo.com" because
            # the base url is at "/foo"
            (" foo.com  ", ParseResult(path="foo.com  ")),
            ("a:\t foo.com", ParseResult(scheme="a", path=" foo.com")),
            (
                "http://f:21/ b ? d # e ",
                ParseResult(
                    scheme="http", netloc="f:21", path="/ b ", query=" d ", fragment=" e "
                ),
            ),
            (
                "lolscheme:x x#x x",
                ParseResult(scheme="lolscheme", path="x x", fragment="x x"),
            ),
            ("http://f:/c", ParseResult(scheme="http", netloc="f:", path="/c")),
            ("http://f:0/c", ParseResult(scheme="http", netloc="f:0", path="/c")),
            # NOTE(willkg): The wpt tests normalize the 0000000000000 to 0 so the
            # netloc should be "f:0".
            (
                "http://f:00000000000000/c",
                ParseResult(scheme="http", netloc="f:00000000000000", path="/c"),
            ),
            # NOTE(willkg): The wpt tests drop the 0000000000000000000 altogether
            # so the netloc should be "f".
            (
                "http://f:00000000000000000000080/c",
                ParseResult(scheme="http", netloc="f:00000000000000000000080", path="/c"),
            ),
            # This is an invalid ipv6 url
            ("http://2001::1]", ValueError),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f:b/c", ParseResult(scheme="http", netloc="f:b", path="/c")),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f: /c", ParseResult(scheme="http", netloc="f: ", path="/c")),
            # NOTE(willkg): The wpt tests show this as a parse error, but our
            # parser "parses" it.
            ("http://f:999999/c", ParseResult(scheme="http", netloc="f:999999", path="/c")),
        ],
    )
    def test_urlparse(uri, expected):
        if inspect.isclass(expected) and issubclass(expected, BaseException):
            with pytest.raises(expected):
                urlparse(uri)
    
        else:
>           parsed = urlparse(uri)
                     ^^^^^^^^^^^^^

tests/test_parse_shim.py:103: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.16/urllib/parse.py:486: in urlparse
    scheme, netloc, url, params, query, fragment = _urlparse(url, scheme, allow_fragments)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib64/python3.16/urllib/parse.py:499: in _urlparse
    scheme, netloc, url, query, fragment = _urlsplit(url, scheme, allow_fragments)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib64/python3.16/urllib/parse.py:646: in _urlsplit
    _checknetloc(netloc)
/usr/lib64/python3.16/urllib/parse.py:547: in _checknetloc
    _validate_port(port)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

port = 999999

    def _validate_port(port):
        if port.isdigit() and port.isascii():
            port = int(port)
        else:
            raise ValueError(f"Port could not be cast to integer value as {port!r}")
        if not (0 <= port <= 65535):
>           raise ValueError("Port out of range 0-65535")
E           ValueError: Port out of range 0-65535

/usr/lib64/python3.16/urllib/parse.py:168: ValueError
=========================== short test summary info ============================
FAILED tests/test_parse_shim.py::test_urlparse[http://f:b/c-expected18] - Val...
FAILED tests/test_parse_shim.py::test_urlparse[http://f: /c-expected19] - Val...
FAILED tests/test_parse_shim.py::test_urlparse[http://f:999999/c-expected20]
====== 3 failed, 405 passed, 1 skipped, 29 deselected, 2 xfailed in 0.47s ======

https://docs.python.org/3.16/whatsnew/3.16.html:
urllib.parse.urlsplit() and urllib.parse.urlparse() now raise ValueError when the URL is parsed if the port is not a decimal number or is outside the range 0–65535. Previously, the error was only raised when the port attribute was read. This also affects urljoin(), and urldefrag() for URLs with a fragment. Code which never read port may now fail on URLs such as:

    SCP-style addresses given a scheme, such as git+ssh://git:org/repo.git;

    multi-host URLs with ports, such as mongodb://h1:27017,h2:27017/db or postgresql://h1:5432,h2:5433/db;

    URL templates with a placeholder port, such as http://localhost:{port}/.

These are not valid URLs under RFC 3986. To process them, split off the netloc yourself before calling urlsplit(), for example by replacing it with a placeholder host, or fill in templates before parsing them. (Contributed by Miguel Brito and Senthil Kumaran in gh-88037.)

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.16/fedora-rawhide-x86_64/11359632-python-bleach/

For all our attempts to build python-bleach with Python 3.16, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.16/package/python-bleach/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.16:
https://copr.fedorainfracloud.org/coprs/g/python/python3.16/

Let us know here if you have any questions.

Python 3.16 is planned to be included in Fedora 47.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.16.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.