Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/fragments/+strict_base64.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Report non-ASCII Base64 input as a loader error for bytes-like values.
2 changes: 2 additions & 0 deletions src/adaptix/_internal/morphing/concrete_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def bytes_base64_loader(data):
encoded = data.encode("ascii")
except AttributeError:
raise TypeLoadError(str, data)
except UnicodeEncodeError:
raise ValueLoadError("Bad base64 string", data)

if not B64_PATTERN.fullmatch(encoded):
raise ValueLoadError("Bad base64 string", data)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/morphing/test_concrete_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ def test_bytes_like_provider(
lambda: loader("Hello, world"),
)

raises_exc(
ValueLoadError("Bad base64 string", "🦄"),
lambda: loader("🦄"),
)

raises_exc(
ValueLoadError(
msg="Invalid base64-encoded string: number of data characters (5) cannot be 1 more than a multiple of 4",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/type_tools/test_normalize_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def test_forward_ref_at_type_var_limit():
P_FR1,
NormParamSpec(
P_FR1,
limit=Bound(nt_zero(int, source=ForwardRef("int"))),
limit=Bound(nt_zero(int, source=P_FR1.__bound__)),
source=P_FR1,
default=None,
),
Expand All @@ -847,7 +847,7 @@ def test_forward_ref_at_type_var_limit():
P_FR2,
NormParamSpec(
P_FR2,
limit=Bound(nt_zero(MyForwardClass, source=ForwardRef("MyForwardClass"))),
limit=Bound(nt_zero(MyForwardClass, source=P_FR2.__bound__)),
source=P_FR2,
default=None,
),
Expand Down
Loading