-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix filesystem error on long HTTP filenames by sanitizing and truncating to 100 bytes #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added truncateFilename function to limit filenames to 100 bytes - Handles Unicode characters properly by truncating at UTF-8 boundaries - Preserves file extensions when possible during truncation - Applied truncation in Resolve method after filename parsing - Added comprehensive unit tests covering various edge cases Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com>
- Defined maxExtensionLength constant for better maintainability - Added documentation explaining the constant's purpose Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1240 +/- ##
==========================================
- Coverage 71.58% 71.55% -0.03%
==========================================
Files 47 47
Lines 5757 5780 +23
==========================================
+ Hits 4121 4136 +15
- Misses 1233 1239 +6
- Partials 403 405 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot 直接一起把 downloader.go 里面的 util.ReplaceInvalidFilename 逻辑也直接挪到http fetcher里面处理,因为只有http下载有这个文件名的问题 |
- Added replaceInvalidFilenameChars() in helper.go - Applied character replacement before truncation in fetcher.go - Added 12 test cases for character replacement - This consolidates filename sanitization in HTTP fetcher only Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com>
Done! Moved the invalid filename character replacement logic into the HTTP fetcher (commit 8099e47). Changes:
This consolidates all filename sanitization (invalid chars + length truncation) in the HTTP protocol layer only, as you suggested. |
- Moved invalidFilenameChars to package-level variable - Avoids repeated slice allocation on each function call - More efficient memory usage Co-authored-by: monkeyWie <13160176+monkeyWie@users.noreply.github.com>
HTTP downloads fail with "filename too long" error when the resolved filename exceeds filesystem limits (typically 255 bytes, but varies by OS). Additionally, filenames with invalid characters can cause file creation errors.
Changes
Added
replaceInvalidFilenameChars()ininternal/protocol/http/helper.go\ / : * ? " < > |) with underscoresAdded
truncateFilename()ininternal/protocol/http/helper.gomaxExtensionLengthconstant (20 bytes) to identify reasonable extensionsApplied sanitization in
Resolve()ininternal/protocol/http/fetcher.goContent-Dispositionheader or URL pathAdded 25 test cases in
internal/protocol/http/filename_parse_test.goExample
The 100-byte limit provides a safe margin across all major filesystems while keeping filenames readable. All filename handling is now consolidated in the HTTP protocol layer since only HTTP downloads have these filename issues.
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.