Skip to content

Fix/multipart stray linebreak - #1

Closed
GitGud44 wants to merge 2 commits into
mainfrom
fix/multipart_stray_linebreak
Closed

Fix/multipart stray linebreak#1
GitGud44 wants to merge 2 commits into
mainfrom
fix/multipart_stray_linebreak

Conversation

@GitGud44

@GitGud44 GitGud44 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Overview

MultipartBody.serialize() writes every string part's value with write_str_value(),
which always appends a trailing newline. That newline therefore becomes part of the value
Itself. E.g. A part meant to hold the value "helloworld" is sent as "helloworld\r\n".
Consumers that compare that value exactly would then reject it.

Fixed by writing string part values with write_bytes_value() instead, which writes raw bytes with no terminator.

Related Issue

Fixes #

Demo

Before (current main), a text/plain part with value "Hello world":

--boundary\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name="message"\r\n\r\nHello world\r\n\r\n--boundary--\r\n

After (this PR):

--boundary\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name="message"\r\n\r\nHello world\r\n--boundary--\r\n

Notes

  • Only string part values are affected. bytes/file parts already go through
    write_bytes_value() and never carried the stray CRLF.
  • No existing test covered a plain str part before this PR, every
    test_write_object_value* case used a JSON (Parsable) part and a bytes part, never
    a bare string one.

Testing Instructions

  • cd packages/serialization/multipart && poetry install
  • poetry run pytest
    ** Expect test_write_object_value_with_string_part and
    test_write_object_value_with_multiple_string_parts to pass (both fail on main
    without this fix (double CRLF before the boundary instead of one))

@GitGud44
GitGud44 marked this pull request as ready for review August 13, 2026 18:51
@GitGud44 GitGud44 closed this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant