fix: Uploaded files with quoted names appear as %22 in chat#39000
fix: Uploaded files with quoted names appear as %22 in chat#39000
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
…t %22 in chat Co-authored-by: ggazzo <5263975+ggazzo@users.noreply.github.com>
| // The HTML5 multipart/form-data encoding algorithm percent-encodes certain characters in filenames: | ||
| // `"` → `%22`, `\r\n` → `%0D%0A`, `\r` → `%0D`, `\n` → `%0A` | ||
| // Busboy does not decode these for regular `filename=` parameters, so we reverse the encoding here. | ||
| const filename = rawFilename.replace(/%0D%0A/gi, '\r\n').replace(/%0D/gi, '\r').replace(/%0A/gi, '\n').replace(/%22/gi, '"'); |
There was a problem hiding this comment.
@copilot do we need to decode line breaks and carret returns for file names? What would be the advantage of doing?
There was a problem hiding this comment.
@copilot do we need to decode line breaks and carret returns for file names? What would be the advantage of doing?
There was a problem hiding this comment.
No advantage — removed the line break decoding in 2c8d382. Decoding %0D/%0A in filenames would only introduce risk (e.g. log injection) with no real-world benefit, since no user would name a file with literal newlines. The fix now only decodes %22 → ", which is the actual issue reported.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #39000 +/- ##
========================================
Coverage 70.64% 70.64%
========================================
Files 3189 3189
Lines 112716 112716
Branches 20413 20413
========================================
Hits 79632 79632
Misses 31040 31040
Partials 2044 2044 🚀 New features to boost your workflow:
|
Co-authored-by: ggazzo <5263975+ggazzo@users.noreply.github.com>
|
@ggazzo ask copilot to mock the imports on the unit tests, an import it's trying to use |
The HTML5 multipart/form-data spec requires browsers to percent-encode
"as%22infilename=Content-Disposition parameters. Busboy only decodes extendedfilename*=parameters (RFC 5987), leaving%22literal — so a file namedThis is "test"was stored in the DB and displayed in chat asThis is %22test%22.Changes
MultipartUploadHandler.ts: Decode%22back to"on the raw filename from busboy before it propagates to storage and message attachments. Applies to all upload paths (/v1/rooms.mediaand/v1/livechat/upload).Other percent sequences (e.g.
%20) are intentionally left untouched to avoid misinterpreting literal%characters in filenames.MultipartUploadHandler.spec.ts: Unit tests covering%22decoding and confirming that%20is not decoded.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.