fix: marshall multi-byte strings correctly (#261)
This commit is contained in:
parent
f9e5d1d020
commit
4de31a3646
@ -68,7 +68,7 @@ class Marshaller:
|
||||
|
||||
def _write_string(self, value: _str) -> int:
|
||||
value_bytes = value.encode()
|
||||
value_len = len(value)
|
||||
value_len = len(value_bytes)
|
||||
written = self._align(4) + 4
|
||||
buf = self._buf
|
||||
buf += PACK_UINT32(value_len)
|
||||
|
||||
@ -242,5 +242,17 @@
|
||||
"body": [["hello", "worl"], true, false, ["hello", "worl"], true, false]
|
||||
},
|
||||
"data": "6c01000148000000010000007e00000001016f00150000002f6f72672f667265656465736b746f702f4442757300000002017300140000006f72672e667265656465736b746f702e4442757300000000030173000500000048656c6c6f00000006017300140000006f72672e667265656465736b746f702e444275730000000008016700086173626261736262000000150000000500000068656c6c6f00000004000000776f726c000000000100000000000000150000000500000068656c6c6f00000004000000776f726c000000000100000000000000"
|
||||
},
|
||||
{
|
||||
"message": {
|
||||
"destination": "org.freedesktop.DBus",
|
||||
"path": "/org/freedesktop/DBus",
|
||||
"interface": "org.freedesktop.DBus",
|
||||
"member": "Hello",
|
||||
"serial": 1,
|
||||
"signature": "as",
|
||||
"body": [["//doesntmatter/über"]]
|
||||
},
|
||||
"data": "6c0100011d000000010000007800000001016f00150000002f6f72672f667265656465736b746f702f4442757300000002017300140000006f72672e667265656465736b746f702e4442757300000000030173000500000048656c6c6f00000006017300140000006f72672e667265656465736b746f702e4442757300000000080167000261730019000000140000002f2f646f65736e746d61747465722fc3bc62657200"
|
||||
}
|
||||
]
|
||||
|
||||
@ -678,3 +678,39 @@ def test_unmarshall_mount_message_2():
|
||||
],
|
||||
[],
|
||||
]
|
||||
|
||||
|
||||
def test_unmarshall_multi_byte_string():
|
||||
"""Test unmarshall a multi-byte string."""
|
||||
|
||||
mount_message = (
|
||||
b"l\x01\x00\x01\x1d\x00\x00\x00"
|
||||
b"\x01\x00\x00\x00x\x00\x00\x00"
|
||||
b"\x01\x01o\x00\x15\x00\x00\x00"
|
||||
b"/org/fre"
|
||||
b"edesktop"
|
||||
b"/DBus\x00\x00\x00"
|
||||
b"\x02\x01s\x00\x14\x00\x00\x00"
|
||||
b"org.free"
|
||||
b"desktop."
|
||||
b"DBus\x00\x00\x00\x00"
|
||||
b"\x03\x01s\x00\x05\x00\x00\x00"
|
||||
b"Hello\x00\x00\x00"
|
||||
b"\x06\x01s\x00\x14\x00\x00\x00"
|
||||
b"org.free"
|
||||
b"desktop."
|
||||
b"DBus\x00\x00\x00\x00"
|
||||
b"\x08\x01g\x00\x02as\x00"
|
||||
b"\x19\x00\x00\x00\x14\x00\x00\x00"
|
||||
b"//doesnt"
|
||||
b"matter/\xc3"
|
||||
b"\xbcber\x00"
|
||||
)
|
||||
|
||||
stream = io.BytesIO(mount_message)
|
||||
unmarshaller = Unmarshaller(stream)
|
||||
unmarshaller.unmarshall()
|
||||
message = unmarshaller.message
|
||||
assert unmarshaller.message.signature == "as"
|
||||
unpacked = unpack_variants(message.body)
|
||||
assert unpacked == [["//doesntmatter/über"]]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user