Fix category headers showing as raw HTML on New Item page#26056
Conversation
Use createElementFromHtml() to properly parse HTML strings instead of treating them as plain text. Fixes jenkinsci#26053
|
Yay, your first pull request towards Jenkins core was created successfully! Thank you so much! |
|
Looks good, thanks. Could you check how it handles illegal characters? |
|
@janfaracik Thanks for checking! I tested createElementFromHtml() with edge cases to verify it handles them safely: Special characters: &, <, >, quotes → all handled correctly 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). Let me know if you'd like to see the test results or have any other concerns! |
janfaracik
left a comment
There was a problem hiding this comment.
Tested locally - looks good to me, thanks!
|
/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! |
|
Congratulations on getting your very first Jenkins core pull request merged 🎉🥳 |
|
Fixed in Jenkins 2.546. |
Fixes #26053
When the
flatclass 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:
node --checkon the file - no syntax errorscreateElementFromHtml()is imported at the top and already used the same way elsewhere in the filenpm run devScreenshots (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 theflatclass is removed fromdiv#itemsas documented in issue #26053.After
Categories render correctly with properly formatted h2 headings and paragraph text.

Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
eval.Desired reviewers
@daniel-beck @jenkinsci/core-pr-reviewers