-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add charset=UTF-8 to Content-Type headers for text-based MIME types #347
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5a1b853
Initial plan
Copilot 2283385
Fix unicode/Chinese character rendering by adding charset=UTF-8 to Co…
Copilot def6d4b
Add charset=UTF-8 to svgz, xhtml, and xht mime types
Copilot 82f27b6
Remove charset from JSON content-type for RFC compliance
Copilot 52b5aa0
Add comprehensive tests and documentation for Unicode fix
Copilot f88e11d
Remove test documentation files and create minimal index.html with Kanji
Copilot 8924e42
Apply suggestion from @brianhuster
brianhuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Test - 漢字</title> | ||
| </head> | ||
| <body> | ||
| <h1>你好世界</h1> | ||
| <p>これは日本語のテストです。</p> | ||
| <p>漢字、ひらがな、カタカナ</p> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Is it necessary to have "charset=UTF-8" here? (This is a question, not a request)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's necessary. Without
charset=UTF-8in the Content-Type header, browsers may default to ISO-8859-1 or other legacy encodings when interpreting text-based files. This causes Unicode characters (Chinese, Japanese, Korean, emoji, etc.) to render as garbled text likeÃ,Æ—‡Åinstead of你好世界.For JavaScript files specifically, this ensures that string literals and comments containing Unicode characters are properly interpreted. While modern browsers often auto-detect UTF-8, the explicit charset declaration guarantees correct rendering across all browsers and prevents encoding issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Should the encoding be got from the buffer-local option
'encoding'?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that wouldn't work in this context. The HTTP server serves files directly from disk using
async_read_file, not from Neovim buffers. Thecontent_type.luamodule runs in the server's context where buffer-local options likeencodingorfileencodingaren't available.Additionally, UTF-8 is the standard encoding for web content. Files on disk are typically UTF-8 encoded (especially for web development), and hardcoding
charset=UTF-8in the HTTP response ensures consistent browser interpretation regardless of the file's actual encoding on disk.