This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/main by this push:
new 221493011 PROTON-2531: Use surrogateescape when reading converting
bytes to string
221493011 is described below
commit 221493011e271cf899a54b596e2b257b4b9904fb
Author: Pete Fawcett <[email protected]>
AuthorDate: Wed Jan 29 17:05:41 2025 +0000
PROTON-2531: Use surrogateescape when reading converting bytes to string
- Add tests to check that binary delivery tags are decoded without
errors.
---
python/cproton.py | 8 ++++----
python/tests/proton_tests/engine.py | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/python/cproton.py b/python/cproton.py
index 528e675b9..6be8711d8 100644
--- a/python/cproton.py
+++ b/python/cproton.py
@@ -200,8 +200,8 @@ def bytes2pybytes(b):
return bytes(ffi.buffer(b.start, b.size))
-def bytes2string(b, encoding='utf8'):
- return ffi.unpack(b.start, b.size).decode(encoding)
+def bytes2string(b, encoding='utf8', errors='surrogateescape'):
+ return ffi.unpack(b.start, b.size).decode(encoding, errors)
def py2bytes(py):
@@ -213,8 +213,8 @@ def py2bytes(py):
return len(s), s
-def string2bytes(py, encoding='utf8'):
- s = ffi.from_buffer(py.encode(encoding))
+def string2bytes(py, encoding='utf8', errors='surrogateescape'):
+ s = ffi.from_buffer(py.encode(encoding, errors))
return len(s), s
diff --git a/python/tests/proton_tests/engine.py
b/python/tests/proton_tests/engine.py
index 1e5f8f476..1b5ab1d2a 100644
--- a/python/tests/proton_tests/engine.py
+++ b/python/tests/proton_tests/engine.py
@@ -978,6 +978,42 @@ class TransferTest(Test):
assert sd.local_state == rd.remote_state == Delivery.ACCEPTED
sd.settle()
+ def test_delivery_tag_bytes(self):
+ test_tags = [
+ (bytes([0, 0, 0, 128]), '\x00\x00\x00\udc80'),
+ ('tag', 'tag'),
+ (b'tag', 'tag'),
+ (bytearray([1, 2, 32, 254, 255]), '\x01\x02 \udcfe\udcff'),
+ (b'\xff'+(29*b' ')+b'\xff\x00', '\udcff
\udcff\x00'),
+ (chr(1024), chr(1024)),
+ (chr(1024) * 32, chr(1024) * 32) # I think this should fail
but it doesn't
+ ]
+
+ self.rcv.flow(len(test_tags))
+
+ self.pump(64 * len(test_tags))
+
+ for (test, _) in test_tags:
+ self.snd.delivery(test)
+ msg = b"this is a test"
+ self.snd.send(msg)
+ assert self.snd.advance()
+
+ self.pump(64 * len(test_tags))
+
+ for (_, expected) in test_tags:
+ rd = self.rcv.current
+ assert rd is not None
+ assert rd.tag == expected, (rd.tag, expected)
+ rd.update(Delivery.ACCEPTED)
+ rd.settle()
+
+ try:
+ self.snd.delivery('\udc80')
+ assert False, "Expected UnicodeEncodeError"
+ except UnicodeEncodeError:
+ pass
+
def test_delivery_id_ordering(self):
self.rcv.flow(1024)
self.pump(buffer_size=64 * 1024)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]