Skip to content

fix(apiform): strip path components from upload filenames - #120

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/apiform-upload-basename
Open

fix(apiform): strip path components from upload filenames#120
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/apiform-upload-basename

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 20, 2026

Copy link
Copy Markdown

Summary

Ensure multipart uploads send only the basename of reader-provided file paths, regardless of whether the path uses POSIX or Windows separators.

Problem

internal/apiform.encodeReader derives filenames from readers exposing Name() with path.Base, which only treats / as a separator. A Windows-style name such as C:\dir\report.pdf can therefore remain unchanged when processed on a non-Windows host or supplied by a cross-platform/custom reader, placing directory components in the multipart filename= parameter instead of just report.pdf.

Fix

Normalize backslash separators before taking the path basename. POSIX paths keep their existing behavior, while Windows-style paths reduce to the same basename representation.

The change is limited to the Name() fallback. Readers that explicitly implement Filename() retain control of the filename they provide.

Regression coverage

Added table-driven multipart tests covering POSIX and Windows-style paths. Both must produce filename="report.pdf", and the serialized body must not contain directory components.

Validation

The branch is based directly on current upstream main (a7719136b8ed401b0c51a05553a5e4f720150307) and contains one DCO-signed commit touching only the multipart encoder plus focused regression coverage. Full repository test execution is left to CI.

Risk

Low. Only the fallback filename derived from a reader's Name() changes, and only by removing directory components. File contents, content type handling, explicit Filename() implementations, field names, and non-file multipart fields are unchanged.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 20, 2026 20:36
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek force-pushed the fix/apiform-upload-basename branch from ff7e2ed to 8095fae Compare August 20, 2026 20:38
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