Skip to content

Add charset UTF-8 to workspace text file responses - #26912

Merged
MarkEWaite merged 2 commits into
jenkinsci:masterfrom
lohitkolluri:fix/26894-workspace-viewer-utf8-charset
Jun 19, 2026
Merged

MarkEWaite merged 2 commits into
jenkinsci:masterfrom
lohitkolluri:fix/26894-workspace-viewer-utf8-charset

Conversation

@lohitkolluri

@lohitkolluri lohitkolluri commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Content-Type header includes charset=utf-8
  • Chinese characters are served correctly (not garbled)

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

  • Include charset=UTF-8 in Content-Type when serving text/* files through the workspace and artifact browser.

Proposed changelog category

/label bug

Proposed upgrade guidelines

N/A

Submitter checklist

  • The issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • UI changes do not introduce regressions when enforcing the current default rules of Content Security Policy Plugin. In particular, new or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-Type to include charset=UTF-8 when serving text/* files from DirectoryBrowserSupport.
  • Ensure the special *view* path serves as text/plain with UTF-8 charset.
  • Add a regression test validating both the Content-Type header and correct round-trip rendering of Chinese characters from a workspace .java file.

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 MarkEWaite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@comment-ops-bot comment-ops-bot Bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Jun 18, 2026
@lohitkolluri

Copy link
Copy Markdown
Contributor Author

Thanks for the review and approval. I appreciate your time and feedback.

@MarkEWaite
MarkEWaite merged commit 928934f into jenkinsci:master Jun 19, 2026
18 checks passed
@welcome

welcome Bot commented Jun 19, 2026

Copy link
Copy Markdown

Congratulations on getting your very first Jenkins core pull request merged 🎉🥳

This is a fantastic achievement, and we're thrilled to have you as part of our community! Thank you for your valuable input, and we look forward to seeing more of your contributions in the future!

We would like to invite you to join the community chats and forums to meet other Jenkins contributors 😊
Don't forget to check out the participation page to learn more about how to contribute to Jenkins.


lohitkolluri added a commit to lohitkolluri/lohitkolluri that referenced this pull request Jun 23, 2026
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ath-successful This PR has successfully passed the full acceptance-test-harness suite bug For changelog: Minor bug. Will be listed after features pct-successful This PR has successfully passed the full plugin-compatibility-test suite ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workspace viewer displays UTF-8 Java source files as garbled text when no charset is specified

3 participants