Skip to content

Move authoring UI inline JS handlers to data attributes - #168

Open
snoopdave wants to merge 3 commits into
masterfrom
authoring-ui-event-handlers
Open

Move authoring UI inline JS handlers to data attributes#168
snoopdave wants to merge 3 commits into
masterfrom
authoring-ui-event-handlers

Conversation

@snoopdave

Copy link
Copy Markdown
Contributor

Several authoring pages embed values in inline JavaScript string literals and
then write them into the page with jQuery .html(). This refactor moves those
values into data attributes and writes them through text APIs, so JSPs stop
hand-concatenating markup and data.

What changed

  • Move server/user-controlled values out of inline JavaScript string literals
    into double-quoted, HTML-escaped data-* attributes.
  • Bind delegated event listeners that read values as text and assign them via
    textContent, .text(), .val(), or DOM constructors.
  • Replace the affected .html() writes with a text API.
  • Use double-quoted attributes for weblog-content values in the media views.
  • Cover templates, bookmarks/folders, categories, media views/chooser/success,
    entry lists, and entry editing, including the category iterator and
    delete-modal cases.
  • Render theme descriptions as text and make ThemeDataServlet return valid
    JSON.

Tests

  • Values containing apostrophes, quotes, angle brackets, backslashes, newlines,
    and </script> remain text through each path.
  • Cross-user authoring cases confirm one author's values stay text in another
    author or administrator session.
  • A source audit confirms no affected value remains in an inline literal, a
    single-quoted attribute, or a .html() sink.

The editor screens built handler arguments by interpolating template values
directly into inline onclick/onchange attributes. Those values now travel in
data-* attributes and are read back through delegated listeners, which matches
how the rest of the UI binds behaviour and keeps markup and data separate.

Writes that placed those values into the DOM now use text APIs rather than
html(), and ThemeDataServlet escapes its JSON output so theme metadata cannot
produce a malformed document.

Adds AuthoringUiSinkAuditTest to keep the editor templates on this pattern.
The media gallery rendered the media file name into single-quoted HTML
attributes; those attributes are now double-quoted so the value stays data.
The sink-audit test description now states the rule it enforces, and the
repeated per-page comment is collapsed to one line.

Claude-Session: https://claude.ai/code/session_01A1fhY1E2PCFU6UAPXu2WtV

@mraible mraible 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.

Reviewed. The output-handling changes are moving in the right direction. Please address the remaining consistency and test-coverage notes before merge.

$('#category-name').html(name);
$('#category-name').text(name);
if ( inUse ) {
$('#category-in-use').css('display','block');

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.

Pre-existing, but since this function is being reworked: lines 294/297 toggle #category-emtpy while the element is #category-empty (line 266), so the "no entries in this category" message never shows.

url: "<s:url value='themedata'/>",
data: {theme: themeId}, success: function (data) {
$('#themeDescription').html(data.description);
$('#themeDescription').text(data.description);

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.

Behaviour change worth a line in the description: a shared theme whose theme.xml <description> carries markup now renders it as literal text. The bundled themes are plain text, so I think that's fine, just disclose it.


<%-- Source data for the "move entries to" select, carried as escaped
attributes rather than generated JavaScript literals. --%>
<div id="category-option-data" style="display:none">

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.

Nit: the .category-edit-link anchors above already carry data-category-id / data-category-name for every category, so populateCategorySelect could read those instead of maintaining a second serialised copy.

}
}

private static String flatten(String source) {

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.

Nit: HANDLER_LITERAL uses \s* and [^"]*, both of which already span newlines, so flatten() / flattenSource don't change any match and can go.

@apache apache deleted a comment from mraible Sep 1, 2026
@apache apache deleted a comment from mraible Sep 1, 2026
@apache apache deleted a comment from mraible Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants