Add charset UTF-8 to workspace text file responses#26912
Open
lohitkolluri wants to merge 2 commits into
Open
Conversation
When viewing source files in the workspace browser, the Content-Type header lacked a charset parameter. Browsers guessed the encoding, which failed for non-ASCII text. The Stapler serveFile mime-type: prefix is now used to explicitly set Content-Type with charset=UTF-8 for text/* files. The *view* path and normal file serving path are both updated. Binary files are unaffected. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
This was referenced Jun 11, 2026
This was referenced Jun 14, 2026
Author
|
Friendly ping @jenkinsci/core-pr-reviewers. All checks are passing, and the issue reporter has confirmed that #26912 resolves the problem in their environment. I'd appreciate any review feedback when time permits. Thanks! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses JENKINS-26894 by ensuring that text files served via DirectoryBrowserSupport (workspace/artifact browser) include an explicit UTF-8 charset in the Content-Type response header, preventing browsers from guessing an incorrect encoding for non-ASCII content.
Changes:
- Force
Content-Typeto includecharset=UTF-8when servingtext/*files fromDirectoryBrowserSupport. - Ensure the special
*view*path serves astext/plainwith UTF-8 charset. - Add a regression test validating both the
Content-Typeheader and correct round-trip rendering of Chinese characters from a workspace.javafile.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/src/main/java/hudson/model/DirectoryBrowserSupport.java | Adds charset=UTF-8 for text/* responses (and *view* text/plain) when serving files. |
| test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java | Adds a regression test verifying charset presence and correct UTF-8 content rendering from workspace browsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Fixes #26894
Testing done
Automated test added that writes a .java file containing Chinese characters (用户中心模块) to a freestyle project workspace, fetches it via the workspace browser, and verifies:
The full DirectoryBrowserSupportTest suite passes (23 tests, 0 failures, 2 skipped for platform-specific reasons).
The view path regression test (canViewRelativePath) also passes.
Screenshots (UI changes only)
N/A - backend change, no visual UI modification.
Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).