Repository navigation
Add charset UTF-8 to workspace text file responses - #26912
MarkEWaite merged 2 commits into
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>
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>
MarkEWaite
left a comment
There was a problem hiding this comment.
This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process.
/label ready-for-merge
|
Thanks for the review and approval. I appreciate your time and feedback. |
|
Congratulations on getting your very first Jenkins core pull request merged 🎉🥳 |
- Add prometheus/prometheus#18996 (compaction docs) - Add jenkinsci/jenkins#26912 (UTF-8 charset for workspace viewer) - Wrap OSS contributions table in scrollable container (top 5 visible) Signed-off-by: Lohit Kolluri <me@lohit.is-a.dev>
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).