feat: Preserve UTF-8 BOM when editing files - #1680
Merged
Merged
Conversation
- Add FileEncoding constants (UTF8, UTF8_BOM) - Add detectFileBOM() to detect existing file encoding - Modify writeTextFile() to support BOM option - Add defaultFileEncoding configuration option - Preserve BOM when editing existing files - Use configured encoding for new files - Add comprehensive tests (unit, integration, e2e) - Update documentation Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
tanzhenxin
requested review from
DennisYu07,
LaZzyMan,
Mingholy,
gwinthis and
pomelo-nwu
as code owners
February 1, 2026 02:34
Contributor
📋 Review SummaryThis PR successfully implements UTF-8 BOM preservation when editing files, addressing Issue #1672. The changes add robust file encoding detection and preservation capabilities while maintaining backward compatibility. The implementation includes proper configuration options, comprehensive test coverage, and follows good TypeScript practices. 🔍 General Feedback
🎯 Specific Feedback🔴 CriticalNo critical issues identified in this review. 🟡 HighNo high priority issues identified in this review. 🟢 Medium
🔵 Low
✅ Highlights
|
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
- Edit tool now respects defaultFileEncoding for new files - Edit tool preserves BOM character for existing files without re-adding - AcpFileSystemService detects BOM through ACP client with fallback - Use line: null, limit: 1 for efficient BOM detection - Add unit tests for AcpFileSystemService.detectFileBOM - Add unit tests for EditTool BOM handling Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
tanzhenxin
force-pushed
the
fix/preserve-utf8-bom-encoding
branch
from
February 1, 2026 03:27
2389396 to
2d525d9
Compare
- Strip BOM character (\uFEFF) from content before prepending BOM bytes - Use FileEncoding.UTF8 constant instead of string literal - Ensure file descriptor is closed in finally block - Add test for double BOM prevention Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
…ding feat: Preserve UTF-8 BOM when editing files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
This PR fixes Issue #1672 by preserving UTF-8 BOM (Byte Order Mark) when Qwen Code edits existing files. It also adds a new configuration option
general.defaultFileEncodingto control the encoding for new files.Dive Deeper
Problem
When Qwen Code edited files with UTF-8 BOM encoding (common in Windows/Visual Studio projects), the BOM was lost, causing encoding detection issues and garbled Chinese characters in some editors.
Solution
FileSystemService Enhancements:
FileEncodingconstants (UTF8, UTF8_BOM)detectFileBOM()method to detect existing file encodingwriteTextFile()to support optional BOM parameterWriteFileTool Improvements:
New Configuration Option:
general.defaultFileEncodingsetting ("utf-8"or"utf-8-bom")"utf-8"for backward compatibilityTesting
Reviewer Test Plan
Create a file with UTF-8 BOM:
Ask Qwen Code to edit the file:
Edit test.js to change x to 2Verify BOM is preserved:
Testing Matrix
Tested on macOS with npm run build and full test suite
Linked issues / bugs
Fixes #1672
🤖 Generated with Qwen Code