Skip to content

Commit

Permalink
Merge branch 'master' into validate_host
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 22, 2024
2 parents b8d12cf + 6795a59 commit 5b7391f
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
shell: bash

- name: Build wheels
uses: pypa/cibuildwheel@v2.20.0
uses: pypa/cibuildwheel@v2.21.1
env:
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection
Expand Down
41 changes: 41 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,47 @@ Changelog

.. towncrier release notes start
1.11.1
======

*(2024-09-09)*


Bug fixes
---------

- Allowed scheme replacement for relative URLs if the scheme does not require a host -- by :user:`bdraco`.

*Related issues and pull requests on GitHub:*
:issue:`280`, :issue:`1138`.

- Allowed empty host for URL schemes other than the special schemes listed in the WHATWG URL spec -- by :user:`bdraco`.

*Related issues and pull requests on GitHub:*
:issue:`1136`.


Features
--------

- Loosened restriction on integers as query string values to allow classes that implement ``__int__`` -- by :user:`bdraco`.

*Related issues and pull requests on GitHub:*
:issue:`1139`.


Miscellaneous internal changes
------------------------------

- Improved performance of normalizing paths -- by :user:`bdraco`.

*Related issues and pull requests on GitHub:*
:issue:`1137`.


----


1.11.0
======

Expand Down
1 change: 0 additions & 1 deletion CHANGES/1136.bugfix.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/1137.misc.rst

This file was deleted.

1 change: 1 addition & 0 deletions CHANGES/1143.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of processing paths -- by :user:`bdraco`.
6 changes: 3 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r cython.txt
covdefaults
idna==3.8
multidict==6.0.5
pytest==8.3.2
idna==3.10
multidict==6.1.0
pytest==8.3.3
pytest-cov>=2.3.1
pytest-xdist
13 changes: 13 additions & 0 deletions tests/test_update_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ class IntEnum(int, enum.Enum):
assert str(url2) == "http://example.com/path?a=1"


def test_with_class_that_implements__int__():
"""Allow classes that implement __int__ to be used in query strings."""

class myint:

def __int__(self):
return 84

url = URL("http://example.com/path")
url2 = url.with_query(a=myint())
assert str(url2) == "http://example.com/path?a=84"


def test_with_float_enum():
class FloatEnum(float, enum.Enum):
A = 1.1
Expand Down
9 changes: 7 additions & 2 deletions tests/test_url_update_netloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ def test_with_scheme_uppercased():


def test_with_scheme_for_relative_url():
with pytest.raises(ValueError):
URL("path/to").with_scheme("http")
"""Test scheme can be set for relative URL."""
msg = "scheme replacement is not allowed for " "relative URLs for the http scheme"
with pytest.raises(ValueError, match=msg):
assert URL("path/to").with_scheme("http")

expected = URL("file:///absolute/path")
assert expected.with_scheme("file") == expected


def test_with_scheme_invalid_type():
Expand Down
2 changes: 1 addition & 1 deletion yarl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cache_info,
)

__version__ = "1.11.1.dev0"
__version__ = "1.11.2.dev0"

__all__ = (
"URL",
Expand Down
19 changes: 11 additions & 8 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Iterable,
Iterator,
List,
SupportsInt,
Tuple,
TypedDict,
TypeVar,
Expand Down Expand Up @@ -806,7 +807,7 @@ def raw_parts(self) -> Tuple[str, ...]:
else:
parts = ["/"] + path[1:].split("/")
else:
if path.startswith("/"):
if path and path[0] == "/":
parts = ["/"] + path[1:].split("/")
else:
parts = path.split("/")
Expand Down Expand Up @@ -885,7 +886,7 @@ def _validate_authority_uri_abs_path(host: str, path: str) -> None:
Raise ValueError if not.
"""
if host and path and not path.startswith("/"):
if host and path and not path[0] == "/":
raise ValueError(
"Path in a URL with authority should start with a slash ('/') if set"
)
Expand Down Expand Up @@ -1074,8 +1075,12 @@ def with_scheme(self, scheme: str) -> "URL":
# N.B. doesn't cleanup query/fragment
if not isinstance(scheme, str):
raise TypeError("Invalid scheme type")
if not self.absolute:
raise ValueError("scheme replacement is not allowed for relative URLs")
if not self.absolute and scheme in SCHEME_REQUIRES_HOST:
msg = (
"scheme replacement is not allowed for "
f"relative URLs for the {scheme} scheme"
)
raise ValueError(msg)
return URL(self._val._replace(scheme=scheme.lower()), encoded=True)

def with_user(self, user: Union[str, None]) -> "URL":
Expand Down Expand Up @@ -1211,9 +1216,7 @@ def _query_var(v: QueryVariable) -> str:
if math.isnan(v):
raise ValueError("float('nan') is not supported")
return str(float(v))
if cls is not bool and issubclass(cls, int):
if TYPE_CHECKING:
assert isinstance(v, int)
if cls is not bool and isinstance(cls, SupportsInt):
return str(int(v))
raise TypeError(
"Invalid variable type: value "
Expand Down Expand Up @@ -1418,7 +1421,7 @@ def with_suffix(self, suffix: str) -> "URL":
"""
if not isinstance(suffix, str):
raise TypeError("Invalid suffix type")
if suffix and not suffix.startswith(".") or suffix == ".":
if suffix and not suffix[0] == "." or suffix == ".":
raise ValueError(f"Invalid suffix {suffix!r}")
name = self.raw_name
if not name:
Expand Down

0 comments on commit 5b7391f

Please sign in to comment.