`yarl.URL.build()` fails when `host=None`
paulpapacz opened this issue · comments
Paul Pa commented
Describe the bug
When building a URL using yarl.URL.build()
the command will fail with exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 248, in build
cls._validate_authority_uri_abs_path(host=host, path=path)
File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 706, in _validate_authority_uri_abs_path
if len(host) > 0 and len(path) > 0 and not path.startswith("/"):
TypeError: object of type 'NoneType' has no len()
To Reproduce
yarl
version 1.8.2
from yarl import URL
URL.build(scheme="http", host=None)
Expected behavior
Either passing without problems or some meaningful error/exception indicating that host
cannot be None
.
Logs/tracebacks
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 248, in build
cls._validate_authority_uri_abs_path(host=host, path=path)
File "/path/to/virtualenv/lib/python3.10/site-packages/yarl/_url.py", line 706, in _validate_authority_uri_abs_path
if len(host) > 0 and len(path) > 0 and not path.startswith("/"):
TypeError: object of type 'NoneType' has no len()
Python Version
$ python --version
Python 3.10.6
multidict Version
$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /path/to/virtualenv/lib/python3.10/site-packages
Requires:
Required-by: aiohttp, yarl
yarl Version
$ python -m pip show yarl
Name: yarl
Version: 1.8.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /path/to/virtualenv/lib/python3.10/site-packages
Requires: idna, multidict
Required-by: aiohttp, template-api
OS
Ubuntu 22.04
Additional context
This should be easy to fix by simply adding the same check for host
as those for scheme
, authority
, etc, in the condition here.
Code of Conduct
- I agree to follow the aio-libs Code of Conduct
Looks like the related PR #809 got merged long ago and was included in v1.9.0.