Skip to content

feat: add opt-in percent-decoded multipart filename accessor - #1497

Merged
pjfanning merged 2 commits into
apache:mainfrom
pjfanning:multipart-percent-decoded-filename
Nov 18, 2026
Merged

pjfanning merged 2 commits into
apache:mainfrom
pjfanning:multipart-percent-decoded-filename

Conversation

@pjfanning

@pjfanning pjfanning commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Motivation

RFC 7578 section 4.2 allows senders to percent-encode non-ASCII form-data filenames, and #1494 added a client-side PercentEncoded option. On the server, filename / getFilename only return the raw value, so a percent-encoded filename sent by a Pekko client cannot be read back as the original name.

Modification

  • Add Scala Multipart.FormData.BodyPart.percentDecodedFilename and a Java getPercentDecodedFilename() default method. They percent-decode the filename parameter as UTF-8 and return the raw value when it is not valid percent-encoded UTF-8 (e.g. 100%.txt, caf%E9.txt).
  • Keep filename / getFilename unchanged. Decoding is opt-in because a literal % is valid in filenames.
  • Document the accessor and note that the filename is untrusted input.
  • Follow-up to feat: make multipart form-data filename encoding selectable #1494: its rendering test skipped 100%.txt for the Extended and Ascii encodings. It now covers all three.

Result

Servers can opt in to reading percent-encoded filenames, so Pekko client to Pekko server round-trips with PercentEncoded.

Tests

  • sbt "http-core/Test/testOnly org.apache.pekko.http.scaladsl.model.MultipartSpec org.apache.pekko.http.javadsl.model.MultipartFilenameTest": passed (decoding cases including invalid escapes and invalid UTF-8; 100%.txt with every filename encoding; Java default method).
  • sbt "http-tests/Test/testOnly org.apache.pekko.http.scaladsl.unmarshalling.MultipartUnmarshallersSpec*": 84 passed (CRLF and LF), including decoding from wire bytes.
  • sbt http-core/mimaReportBinaryIssues, javafmtCheckAll, http-core/scalafmtCheckAll, http-tests/scalafmtCheckAll: passed.

References

Fixes #1496. Refs #1494, #1478.

@pjfanning pjfanning added this to the 2.1.0 milestone Nov 18, 2026
Motivation:
RFC 7578 allows senders to percent-encode non-ASCII form-data filenames,
and apache#1494 added a client-side PercentEncoded option, but servers could
only read the raw filename.

Modification:
Add Scala percentDecodedFilename and Java getPercentDecodedFilename to
form-data body parts. They decode UTF-8 percent-escapes and return the
raw value when it is not valid percent-encoded UTF-8. filename and
getFilename are unchanged. Document the accessor in the HTTP model docs.

Result:
Applications can opt in to reading percent-encoded filenames.

Tests:
- MultipartSpec, MultipartFilenameTest, MultipartUnmarshallersSpec

References:
Fixes apache#1496
@pjfanning
pjfanning force-pushed the multipart-percent-decoded-filename branch from bd11e04 to 0bb93b7 Compare November 18, 2026 09:32
@pjfanning
pjfanning requested a review from He-Pin November 18, 2026 10:05
@pjfanning
pjfanning merged commit 18ad1da into apache:main Nov 18, 2026
6 checks passed
@pjfanning
pjfanning deleted the multipart-percent-decoded-filename branch November 18, 2026 11:28
He-Pin added a commit that referenced this pull request Nov 28, 2026
Motivation:
Existing multipart cases cover ordered same-name files and optional
filename decoding but not literal consecutive ASCII spaces in filenames.

Modification:
Round-trip one short modeled multipart part through strict and streamed
form data. Assert the quoted filename in strict output and compare the
complete decoded part, including the name, content, and filename.

Result:
Both entity forms protect the existing behavior of preserving both
spaces. No production code, API, or network behavior changes.

Tests:
- JDK 17, Scala 2.13.18 and 3.3.9: 8/8 each across the two
  MultipartUnmarshallersSpec suite classes, including the new round-trip
  in each and the adjacent same-name and percent-decoding controls.
  Exact test source was compiled against source-matching cached runtime
  classes. The new fixture uses the normal renderer's CRLF in both suites.
- Scoped Scalafmt 3.11.5 and git diff --check passed.
- Full sbt CI was not run.

References:
Refs #1483 and #1497; RFC 7578 Section 4.2.
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.

Support reading percent-encoded multipart/form-data filenames on the server

2 participants