MultipartBody incorrectly appends a new line to string values

Aperta Adatta ai principianti
#2,257 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Inizia individuando MultipartBody e la relativa logica di serializzazione multipart, poi controlla come vengono scritti i valori stringa delle parti e i separatori di boundary. Aggiungi o aggiorna un test di serializzazione mirato per un valore stringa senza newline finale; l’output dovrebbe posizionare correttamente il CRLF del boundary, senza aggiungere un newline extra al valore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The following code:

import com.microsoft.kiota.MultipartBody;

MultipartBody body = new MultipartBody();
body.addOrReplacePart("fileCreatedAt",  "text/plain", "2026-11-15T22:54:31.014Z");

Produces the following output, which has an incorrect extra \r\n after the value and before the separator:

--db526cd4e4a945aaa9f079d8c9497dbf
Content-Type: text/plain
Content-Disposition: form-data; name="fileCreatedAt"

2026-11-15T22:54:31.014Z

--db526cd4e4a945aaa9f079d8c9497dbf--

The correct serialisation should have the value on the line directly preceding the separator. I ran into issue with the current implementation with services (correctly) adding the new line to the end of the value, which then failed to match their validation regex.

The correct serialisation is:

--db526cd4e4a945aaa9f079d8c9497dbf
Content-Type: text/plain
Content-Disposition: form-data; name="fileCreatedAt"

2026-11-15T22:54:31.014Z
--db526cd4e4a945aaa9f079d8c9497dbf--

As per: https://www.rfc-editor.org/info/rfc2046/#section-5.1.1

NOTE: The CRLF preceding the boundary delimiter line is conceptually
attached to the boundary so that it is possible to have a part that
does not end with a CRLF (line break). Body parts that must be
considered to end with line breaks, therefore, must have two CRLFs
preceding the boundary delimiter line, the first of which is part of
the preceding body part, and the second of which is part of the
encapsulation boundary.

Happy to send you a PR to fix this if that would be useful.

Lingua principale
Java
Stelle
38
Fork
37
Merge medio
1g 2h
PR unite (30g)
42

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/kiota-java

Tutte le issue di microsoft/kiota-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.