Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix category headers showing as raw HTML on New Item page#26056

Merged
janfaracik merged 2 commits into
jenkinsci:masterfrom
Abhijeet212004:fix/category-html-rendering-26053
Jan 7, 2026
Merged

Fix category headers showing as raw HTML on New Item page#26056
janfaracik merged 2 commits into
jenkinsci:masterfrom
Abhijeet212004:fix/category-html-rendering-26053

Conversation

@Abhijeet212004
Copy link
Copy Markdown
Contributor

@Abhijeet212004 Abhijeet212004 commented Jan 4, 2026

Fixes #26053

When the flat class is removed from the items container on the New Item page, category titles and descriptions show up as raw HTML text (like <h2>Freestyle projects</h2>) instead of being rendered as proper HTML elements.

This is a regression from PR #10208 which migrated the page from jQuery to vanilla JavaScript. The problem is that jQuery's .append() automatically parses HTML strings, but vanilla JS .append() treats strings as plain text nodes.

The fix: I wrapped the title and description strings with createElementFromHtml() before appending them. This function is already imported and used elsewhere in the same file (lines 123, 128, 129), so it follows the existing pattern.

Testing done

I tested this by:

  • Running node --check on the file - no syntax errors
  • Confirming createElementFromHtml() is imported at the top and already used the same way elsewhere in the file
  • Successfully building the frontend with npm run dev
  • The change is just 2 lines, wrapping existing variables with the helper function

Screenshots (UI changes only)

Before

Categories display as literal HTML strings (<h2>Freestyle projects</h2><p>This is the central feature...</p>) instead of rendered elements. This happens when the flat class is removed from div#items as documented in issue #26053.
Screenshot 2026-01-05 at 11 35 43 AM

After

Categories render correctly with properly formatted h2 headings and paragraph text.
Screenshot 2026-01-05 at 11 37 10 AM

Proposed changelog entries

  • N/A

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.
  • There is automated testing or an explanation as to why this change has no tests.
  • 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.

Desired reviewers

@daniel-beck @jenkinsci/core-pr-reviewers

Use createElementFromHtml() to properly parse HTML strings
instead of treating them as plain text.

Fixes jenkinsci#26053
@welcome
Copy link
Copy Markdown

welcome Bot commented Jan 4, 2026

Yay, your first pull request towards Jenkins core was created successfully! Thank you so much!

A contributor will provide feedback soon. Meanwhile, you can join the chats and community forums to connect with other Jenkins users, developers, and maintainers.

@comment-ops-bot comment-ops-bot Bot added the bug For changelog: Minor bug. Will be listed after features label Jan 4, 2026
@janfaracik
Copy link
Copy Markdown
Member

Looks good, thanks. Could you check how it handles illegal characters?

@Abhijeet212004
Copy link
Copy Markdown
Contributor Author

@janfaracik Thanks for checking! I tested createElementFromHtml() with edge cases to verify it handles them safely:

Special characters: &, <, >, quotes → all handled correctly
Malformed HTML (unclosed tags) → browser auto-closes gracefully
Script tags → NOT executed (template content is inert)
Unicode characters → rendered properly

The function uses HTML5's element, where content is parsed but remains inert (scripts don't execute). This is the same secure pattern already used elsewhere in this file (lines 123, 128, 129).
The category data comes from Jenkins backend API (itemCategories?depth=3), controlled by plugin developers, not user input. This fix simply restores the behavior from before PR #10208, using the standard helper function.

Let me know if you'd like to see the test results or have any other concerns!

Copy link
Copy Markdown
Member

@janfaracik janfaracik left a comment

Choose a reason for hiding this comment

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

Tested locally - looks good to me, thanks!

@janfaracik
Copy link
Copy Markdown
Member

/label ready-for-merge

This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@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 Jan 6, 2026
@janfaracik janfaracik merged commit 96f17d5 into jenkinsci:master Jan 7, 2026
18 checks passed
@welcome
Copy link
Copy Markdown

welcome Bot commented Jan 7, 2026

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.


@Abhijeet212004 Abhijeet212004 deleted the fix/category-html-rendering-26053 branch January 7, 2026 16:51
@Abhijeet212004 Abhijeet212004 restored the fix/category-html-rendering-26053 branch January 7, 2026 16:51
@MarkEWaite
Copy link
Copy Markdown
Contributor

Fixed in Jenkins 2.546.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features 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.

New item page categories show as raw HTML (regression in #10208)

5 participants