fix encoding

This commit is contained in:
Will McGugan
2024-08-20 16:51:02 +01:00
parent 786837399c
commit 83ad5b2972
2 changed files with 11 additions and 1 deletions

View File

@@ -93,7 +93,8 @@ def dump(data: object) -> bytes:
Returns:
The encoded bytes.
"""
return b"s%i:%s" % (len(datum), datum.encode("utf-8"))
encoded_data = datum.encode("utf-8")
return b"s%i:%s" % (len(encoded_data), encoded_data)
def encode_list(datum: list) -> bytes:
"""

View File

@@ -15,6 +15,7 @@ from textual._binary_encode import DecodeError, dump, load
1,
100,
"",
"💩",
"Hello",
b"World",
b"",
@@ -22,10 +23,18 @@ from textual._binary_encode import DecodeError, dump, load
(),
[None],
[1, 2, 3],
(0, "foo"),
(1, "foo"),
(0, ""),
("", "💩", "💩💩"),
(""),
["hello", "world"],
["hello", b"world"],
("hello", "world"),
("hello", b"world"),
("foo", "bar", "baz"),
("foo " * 1000, "bar " * 100, "baz " * 500),
(1, "foo", "bar", "baz"),
{},
{"foo": "bar"},
{"foo": "bar", b"egg": b"baz"},