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
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------
- Preserve leading and trailing CR/LF bytes in binary SOAP attachments
(#1249, #1481).

4.3.3 (2026-06-18)
------------------
- Wire up the ``forbid_external`` setting (previously defined but unused
Expand Down
3 changes: 1 addition & 2 deletions src/zeep/wsdl/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def content(self):

if encoding == "base64":
return base64.b64decode(content)
elif encoding == "binary":
return content.strip(b"\r\n")
else:
# MultipartDecoder has already removed the MIME boundary framing.
return content
35 changes: 32 additions & 3 deletions tests/test_soap_xop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from io import StringIO

import pytest
import requests_mock
from lxml import etree
from pretend import stub
Expand Down Expand Up @@ -68,14 +69,41 @@ def test_rebuild_xml():
<submitClaim>
<accountNumber>5XJ45-3B2</accountNumber>
<eventType>accident</eventType>
<image xop-mime:content-type="image/jpeg">Li4uYmluYXJ5IEpQRyBpbWFnZS4uLg==</image>
<image xop-mime:content-type="image/jpeg">Li4uYmluYXJ5IEpQRyBpbWFnZS4uLg0K</image>
</submitClaim>
</soap:Body>
</soap:Envelope>
"""
assert_nodes_equal(etree.tostring(document), expected)


@pytest.mark.parametrize(
"content",
[
b"binary\r\n",
b"\r\nbinary",
b"\r\nbinary\r\n",
b"\r\n",
b"\x00\xff\r\n",
b"binary",
b"",
],
)
def test_binary_attachment_preserves_content(content):
data = (
b"--MIME_boundary\r\n"
b"Content-Type: application/octet-stream\r\n"
b"Content-Transfer-Encoding: binary\r\n"
b"Content-ID: <attachment@test>\r\n\r\n"
+ content
+ b"\r\n--MIME_boundary--\r\n"
)
decoder = MultipartDecoder(data, "multipart/related; boundary=MIME_boundary")
assert decoder.parts[0].content == content
message_pack = MessagePack(parts=decoder.parts)
assert message_pack.attachments[0].content == content


def get_client_service():
wsdl_main = StringIO(
"""
Expand Down Expand Up @@ -249,7 +277,8 @@ def test_xop():
headers={"Content-Type": content_type},
)
result = service.TestOperation2("")
assert result["_value_1"] == b"BINARYDATA"
# The extra CRLF before the MIME boundary belongs to the binary payload.
assert result["_value_1"] == b"BINARYDATA\r\n"

m.post(
"http://tests.python-zeep.org/test",
Expand Down Expand Up @@ -302,4 +331,4 @@ def test_xop_cid_encoded():
headers={"Content-Type": content_type},
)
result = service.TestOperation2("")
assert result["_value_1"] == b"BINARYDATA"
assert result["_value_1"] == b"BINARYDATA\r\n"