diff --git a/CHANGES/808.bugfix.rst b/CHANGES/808.bugfix.rst new file mode 100644 index 000000000..0f95de744 --- /dev/null +++ b/CHANGES/808.bugfix.rst @@ -0,0 +1 @@ +Made :py:meth:`URL.build` raise a :py:exc:`TypeError` if the ``host`` argument is :py:data:`None` — by :user:`paulpapacz`. diff --git a/tests/test_url_build.py b/tests/test_url_build.py index fc9ccc1d3..51969fa84 100644 --- a/tests/test_url_build.py +++ b/tests/test_url_build.py @@ -239,6 +239,11 @@ def test_build_with_authority_with_path_without_leading_slash(): URL.build(scheme="http", host="example.com", path="path_without_leading_slash") +def test_build_with_none_host(): + with pytest.raises(TypeError, match="NoneType is illegal for.*host"): + URL.build(scheme="http", host=None) + + def test_build_with_none_path(): with pytest.raises(TypeError): URL.build(scheme="http", host="example.com", path=None) diff --git a/yarl/_url.py b/yarl/_url.py index 39fcfa194..e21c5e96e 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -240,12 +240,13 @@ def build( if ( scheme is None or authority is None + or host is None or path is None or query_string is None or fragment is None ): raise TypeError( - 'NoneType is illegal for "scheme", "authority", "path", ' + 'NoneType is illegal for "scheme", "authority", "host", "path", ' '"query_string", and "fragment" args, use empty string instead.' )