Skip to content

fix(transport): handle pathless IO objects in multipart encoding and normalize FilePart filename - #101

Open
Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/multipart-pathless-io
Open

Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/multipart-pathless-io

Conversation

@Adityakk9031

Copy link
Copy Markdown

This PR addresses two related issues when handling IO objects during multipart form-data requests:

  1. Pathless IO objects in write_multipart_chunk:

    • write_multipart_chunk matched in Pathname | IO and called ::File.basename(val.to_path).
    • For IO objects not backed by filesystem paths (such as IO.pipe, sockets, or in-memory streams), val.to_path is nil. Calling ::File.basename(nil) raised a TypeError: no implicit conversion of nil into String, crashing the request.
    • Now checks in IO unless val.to_path.nil? before extracting a filename.
  2. FilePart filename basename and missing pathname require:

    • In FilePart#initialize, passing an IO (e.g. File.open(...)) stored content.to_path directly, retaining full directory paths (unlike Pathname and explicit filenames which use basename). It now normalizes via content.to_path&.then { ::File.basename(_1) }.
    • Added require "pathname" to file_part.rb to prevent NameError: uninitialized constant ContextDev::FilePart::Pathname when FilePart is loaded standalone.

Added tests for pathless IO multipart encoding and FilePart filename extraction.

cc @contextualbeer

@Adityakk9031

Copy link
Copy Markdown
Author

Hi @contextualbeer, whenever you have a chance, could you please take a look at this PR? Thank you!

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