This is an automated email from the ASF dual-hosted git repository.

snoopdave pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git


The following commit(s) were added to refs/heads/master by this push:
     new 6bb6060b6 Move authoring UI inline JS handlers to data attributes 
(#168)
6bb6060b6 is described below

commit 6bb6060b62a14fd81fac41c7e6e00fa5f09ced91
Author: David M. Johnson <[email protected]>
AuthorDate: Sat Sep 5 16:45:08 2026 -0400

    Move authoring UI inline JS handlers to data attributes (#168)
    
    * Move authoring UI inline JS handlers to data attributes
    
    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.
    
    * Double-quote authoring UI media attributes and tighten the sink audit
    
    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
    
    * Finish authoring UI text handling
---
 .../ui/struts2/ajax/ThemeDataServlet.java          |  13 +-
 .../main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp |   2 +-
 .../main/webapp/WEB-INF/jsps/editor/Bookmarks.jsp  |  40 ++++--
 .../main/webapp/WEB-INF/jsps/editor/Categories.jsp |  57 +++++---
 .../main/webapp/WEB-INF/jsps/editor/Comments.jsp   |   2 +-
 .../main/webapp/WEB-INF/jsps/editor/Entries.jsp    |  15 +-
 .../main/webapp/WEB-INF/jsps/editor/EntryEdit.jsp  |  15 +-
 .../WEB-INF/jsps/editor/MediaFileAddSuccess.jsp    |   9 +-
 .../WEB-INF/jsps/editor/MediaFileImageChooser.jsp  |  23 ++--
 .../webapp/WEB-INF/jsps/editor/MediaFileView.jsp   |  54 ++++----
 .../webapp/WEB-INF/jsps/editor/TemplateEdit.jsp    |  16 ++-
 .../main/webapp/WEB-INF/jsps/editor/Templates.jsp  |  12 +-
 .../main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp  |   2 +-
 .../struts2/editor/AuthoringUiSinkAuditTest.java   | 153 +++++++++++++++++++++
 14 files changed, 324 insertions(+), 89 deletions(-)

diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/ajax/ThemeDataServlet.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/ajax/ThemeDataServlet.java
index 694c736dd..bf395a2a0 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/ajax/ThemeDataServlet.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/ajax/ThemeDataServlet.java
@@ -17,6 +17,7 @@
  */
 package org.apache.roller.weblogger.ui.struts2.ajax;
 
+import org.apache.commons.text.StringEscapeUtils;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.business.themes.SharedTheme;
@@ -80,17 +81,21 @@ public class ThemeDataServlet extends HttpServlet {
         }
         for (Iterator<SharedTheme> it = themes.iterator(); it.hasNext();) {
             SharedTheme theme = it.next();
+            // Theme metadata comes from theme.xml, which an operator can edit
+            // or install; escape it so a quote or newline cannot break out of
+            // the string and produce malformed JSON.
             pw.print("    { \"id\" : \"");
-            pw.print(theme.getId());
+            pw.print(StringEscapeUtils.escapeJson(theme.getId()));
             pw.print("\", ");
             pw.print("\"name\" : \"");
-            pw.print(theme.getName());
+            pw.print(StringEscapeUtils.escapeJson(theme.getName()));
             pw.print("\", ");
             pw.print("\"description\" : \"");
-            pw.print(theme.getDescription());
+            pw.print(StringEscapeUtils.escapeJson(theme.getDescription()));
             pw.print("\", ");
             pw.print("\"previewPath\" : \"");
-            pw.print("/themes" + "/" + theme.getId() + "/" + 
theme.getPreviewImage().getPath());
+            pw.print(StringEscapeUtils.escapeJson(
+                    "/themes" + "/" + theme.getId() + "/" + 
theme.getPreviewImage().getPath()));
             pw.print("\" }");
             if (it.hasNext()) {
                 pw.println(", ");
diff --git a/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp 
b/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
index 48c4f08f1..b574975fc 100644
--- a/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
@@ -115,7 +115,7 @@
     function previewImage(themeId) {
         $.ajax({ url: "<s:property value='siteURL' 
/>/roller-ui/authoring/themedata",
             data: {theme:themeId}, success: function(data) {
-                $('#themedescription').html(data.description);
+                $('#themedescription').text(data.description);
                 $('#themeThumbnail').attr('src','<s:property value="siteURL" 
/>' + data.previewPath);
             }
         });
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Bookmarks.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/Bookmarks.jsp
index d004596b2..9c9889509 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Bookmarks.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Bookmarks.jsp
@@ -131,7 +131,7 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
 
                     <td>
                         <s:if test="#bookmark.url != null">
-                            <a href='<s:property value="#bookmark.url" />' 
target='_blank'>
+                            <a href="<s:property value="#bookmark.url" />" 
target="_blank">
                                 <str:truncateNicely lower="70" upper="90">
                                     <s:property value="#bookmark.url"/>
                                 </str:truncateNicely>
@@ -143,13 +143,13 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
 
                     <td align="center">
 
-                        <a href="#" onclick="editBookmark(
-                                '<s:property value="#bookmark.id"/>',
-                                '<s:property value="#bookmark.name"/>',
-                                '<s:property value="#bookmark.url"/>',
-                                '<s:property value="#bookmark.feedUrl"/>',
-                                '<s:property value="#bookmark.description"/>',
-                                '<s:property value="#bookmark.image"/>' )">
+                        <a href="#" class="bookmark-edit-link"
+                           data-bookmark-id="<s:property 
value="#bookmark.id"/>"
+                           data-bookmark-name="<s:property 
value="#bookmark.name"/>"
+                           data-bookmark-url="<s:property 
value="#bookmark.url"/>"
+                           data-bookmark-feed-url="<s:property 
value="#bookmark.feedUrl"/>"
+                           data-bookmark-description="<s:property 
value="#bookmark.description"/>"
+                           data-bookmark-image="<s:property 
value="#bookmark.image"/>">
                             <span class="glyphicon glyphicon-edit"></span>
                         </a>
 
@@ -338,7 +338,7 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
 
     function confirmDeleteFolder() {
         
$('#boomarks_delete_folder_folderId').val($('#bookmarks_folderId:first').val());
-        $('#deleteBlogrollName').html('<s:property value="%{folder.name}"/>');
+        
$('#deleteBlogrollName').text($('#deleteBlogrollName').data('folder-name'));
         $('#delete-blogroll-modal').modal({show: true});
     }
 
@@ -565,7 +565,8 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
 
                 <div class="modal-body">
                     <s:text name="blogrollDeleteOK.areYouSure" />
-                    <span id="deleteBlogrollName"></span>?
+                    <span id="deleteBlogrollName"
+                          data-folder-name="<s:property 
value="%{folder.name}"/>"></span>?
                 </div>
 
                 <div class="modal-footer">
@@ -700,12 +701,23 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
         $('#bookmarkEdit_bean_image:first').val('');
         $('#bookmarkEdit_bean_feedUrl:first').val('');
 
-        $('#subtitle_folder_name:first').html(originalName);
+        $('#subtitle_folder_name:first').text(originalName);
 
         $('#addedit-bookmark-modal').modal({show: true});
     }
 
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.bookmark-edit-link', function (event) {
+        event.preventDefault();
+        editBookmark($(this).attr('data-bookmark-id'),
+                $(this).attr('data-bookmark-name'),
+                $(this).attr('data-bookmark-url'),
+                $(this).attr('data-bookmark-feed-url'),
+                $(this).attr('data-bookmark-description'),
+                $(this).attr('data-bookmark-image'));
+    });
+
     function editBookmark(id, name, url, feedUrl, description, image) {
 
         var saveBookmarkButton = $('#save_bookmark:first');
@@ -725,7 +737,7 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
         $('#bookmarkEdit_bean_description:first').val(description);
         $('#bookmarkEdit_bean_image:first').val(image);
 
-        $('#subtitle_folder_name:first').html(originalName);
+        $('#subtitle_folder_name:first').text(originalName);
 
         $('#addedit-bookmark-modal').modal({show: true});
     }
@@ -770,7 +782,7 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
             elem.removeClass("alert-info");
             elem.removeClass("alert-danger");
             elem.addClass("alert-success");
-            elem.html(message);
+            elem.text(message);
 
         } else {
             saveBookmarkButton.attr("disabled", true);
@@ -789,7 +801,7 @@ We used to call them Bookmarks and Folders, now we call 
them Blogroll links and
             elem.removeClass("alert-info");
             elem.removeClass("alert-success");
             elem.addClass("alert-danger");
-            elem.html(message);
+            elem.text(message);
         }
     }
 
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Categories.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/Categories.jsp
index 6e1d649bd..9082a05b3 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Categories.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Categories.jsp
@@ -55,11 +55,11 @@
                         <s:set var="categoryName"  value="#category.name" />
                         <s:set var="categoryDesc"  
value="#category.description" />
                         <s:set var="categoryImage" value="#category.image" />
-                        <a href="#" onclick="showCategoryEditModal(
-                                '<s:property value="categoryId" />',
-                                '<s:property value="categoryName"/>',
-                                '<s:property value="categoryDesc"/>',
-                                '<s:property value="categoryImage"/>' )">
+                        <a href="#" class="category-edit-link"
+                           data-category-id="<s:property value="categoryId" />"
+                           data-category-name="<s:property 
value="categoryName"/>"
+                           data-category-desc="<s:property 
value="categoryDesc"/>"
+                           data-category-image="<s:property 
value="categoryImage"/>">
                             <span class="glyphicon glyphicon-edit"></span>
                         </a>
 
@@ -71,10 +71,10 @@
                             <s:set var="categoryId"    value="#category.id" />
                             <s:set var="categoryName"  value="#category.name" 
/>
                             <s:set var="categoryInUse" 
value="#category.inUse.toString()" />
-                            <a href="#" onclick="showCategoryDeleteModal(
-                                    '<s:property value="categoryId" />',
-                                    '<s:property value="categoryName" />',
-                                    <s:property value="categoryInUse"/> )" >
+                            <a href="#" class="category-delete-link"
+                               data-category-id="<s:property 
value="categoryId" />"
+                               data-category-name="<s:property 
value="categoryName" />"
+                               data-category-in-use="<s:property 
value="categoryInUse"/>">
                                 <span class="glyphicon glyphicon-trash"></span>
                             </a>
 
@@ -288,27 +288,28 @@
     function showCategoryDeleteModal( id, name, inUse ) {
         $('#categoryRemove_removeId').val(id);
         $('#categoryEdit_bean_name').val(name);
-        $('#category-name').html(name);
+        $('#category-name').text(name);
         if ( inUse ) {
             $('#category-in-use').css('display','block');
-            $('#category-emtpy').css('display', 'none');
+            $('#category-empty').css('display', 'none');
         } else {
             $('#category-in-use').css('display', 'none');
-            $('#category-emtpy').css('display', 'block');
+            $('#category-empty').css('display', 'block');
         }
         populateCategorySelect(id);
         $('#delete-category-modal').modal({show: true});
     }
 
     function populateCategorySelect(removeId) {
-        const allCategories = [];
-
-        <s:iterator value="allCategories" var="category">
-        allCategories.push({
-            id: '<s:property value="#category.id"/>',
-            name: '<s:property value="#category.name"/>'
-        });
-        </s:iterator>
+        // Category names are author-supplied. They are rendered into data
+        // attributes below and read back as text here, so no name is ever
+        // parsed as JavaScript.
+        const allCategories = $('.category-delete-link').map(function () {
+            return {
+                id: $(this).attr('data-category-id'),
+                name: $(this).attr('data-category-name')
+            };
+        }).get();
 
         const select = $('#categoryRemove_targetCategoryId');
         select.empty();
@@ -319,4 +320,20 @@
         });
     }
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.category-edit-link', function (event) {
+        event.preventDefault();
+        showCategoryEditModal($(this).attr('data-category-id'),
+                $(this).attr('data-category-name'),
+                $(this).attr('data-category-desc'),
+                $(this).attr('data-category-image'));
+    });
+
+    $(document).on('click', '.category-delete-link', function (event) {
+        event.preventDefault();
+        showCategoryDeleteModal($(this).attr('data-category-id'),
+                $(this).attr('data-category-name'),
+                $(this).attr('data-category-in-use') === 'true');
+    });
+
 </script>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Comments.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/Comments.jsp
index 78c3f7d71..8d3d41721 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Comments.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Comments.jsp
@@ -276,7 +276,7 @@
                                         <s:if test="#comment.url != null && 
!#comment.url.equals('')">
                                             <div class="details">
                                                 <s:text 
name="commentManagement.commentByURL"/>&nbsp;:&nbsp;
-                                                <a href='<s:property 
value="#comment.url" />'>
+                                                <a href="<s:property 
value="#comment.url" />">
                                                     <str:truncateNicely 
upper="60" appendToEnd="..."><s:property
                                                             
value="#comment.url"/></str:truncateNicely></a>
                                             </div>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Entries.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/Entries.jsp
index 438b1ed00..db793bb43 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Entries.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Entries.jsp
@@ -140,8 +140,9 @@
     <td>
         <s:set var="postId" value="#post.id" />
         <s:set var="postTitle" value="#post.title" />
-        <a href="#"
-            onclick="showDeleteModal('<s:property value="postId" />', 
'<s:property value="postTitle"/>' )">
+        <a href="#" class="entry-delete-link"
+            data-post-id="<s:property value="postId" />"
+            data-post-title="<s:property value="postTitle"/>">
             <span class="glyphicon glyphicon-trash"
                   data-toggle="tooltip" data-placement="top" title="<s:text 
name='generic.delete'/>">
             </span>
@@ -238,9 +239,15 @@
 
 <script>
     function showDeleteModal( postId, postTitle ) {
-        $('#postIdLabel').html(postId);
-        $('#postTitleLabel').html(postTitle);
+        $('#postIdLabel').text(postId);
+        $('#postTitleLabel').text(postTitle);
         $('#removeId').val(postId);
         $('#delete-entry-modal').modal({show: true});
     }
+
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.entry-delete-link', function (event) {
+        event.preventDefault();
+        showDeleteModal($(this).attr('data-post-id'), 
$(this).attr('data-post-title'));
+    });
 </script>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/EntryEdit.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/EntryEdit.jsp
index 7677d2489..14fa8a880 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/EntryEdit.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/EntryEdit.jsp
@@ -291,9 +291,10 @@
 
         <%-- delete --%>
         <span style="float:right">
-            <input class="btn btn-danger" type="button"
+            <input class="btn btn-danger entry-delete-button" type="button"
                    value="<s:text name='weblogEdit.deleteEntry'/>"
-                   onclick="showDeleteModal('<s:property value="entry.id" />', 
'<s:property value="entry.title"/>' )">
+                   data-post-id="<s:property value="entry.id" />"
+                   data-post-title="<s:property value="entry.title"/>">
         </span>
     </s:if>
 
@@ -423,10 +424,16 @@
     });
 
     function showDeleteModal(postId, postTitle) {
-        $('#postIdLabel').html(postId);
-        $('#postTitleLabel').html(postTitle);
+        $('#postIdLabel').text(postId);
+        $('#postTitleLabel').text(postTitle);
         $('#removeId').val(postId);
         $('#delete-entry-modal').modal({show: true});
     }
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.entry-delete-button', function (event) {
+        event.preventDefault();
+        showDeleteModal($(this).attr('data-post-id'), 
$(this).attr('data-post-title'));
+    });
+
 </script>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp
index c3cbae0f2..a8a9572a9 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp
@@ -95,8 +95,8 @@
                     <div class="row">
 
                         <div class="col-md-1">
-                            <input type="radio" name="enclosure"
-                                   onchange="setEnclosure('<s:property 
value="%{#newFile.permalink}"/>')"/>
+                            <input type="radio" name="enclosure" 
class="enclosure-choice"
+                                   data-enclosure-url="<s:property 
value="%{#newFile.permalink}"/>"/>
                         </div>
 
                         <div class="col-md-11">
@@ -201,6 +201,11 @@
         return false;
     }
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('change', '.enclosure-choice', function () {
+        setEnclosure($(this).attr('data-enclosure-url'));
+    });
+
     function setEnclosure(url) {
         $("#enclosureURL").get(0).value = url;
         if (isImageChecked()) {
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileImageChooser.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileImageChooser.jsp
index dddd4d07a..c02dcb64a 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileImageChooser.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileImageChooser.jsp
@@ -72,16 +72,16 @@
                             <li class="align-images"
                                 onmouseover="highlight(this, true)" 
onmouseout="highlight(this, false)">
 
-                                <div class="mediaObject"
-                                     onclick="onSelectMediaFile('<s:property 
value="#mediaFile.name"/>',
-                                             '<s:property 
value="%{mediaFileURL}"/>',
-                                             '<s:property 
value="#mediaFile.isImageFile()"/>')">
+                                <div class="mediaObject 
mediafile-select-target"
+                                     data-mediafile-name="<s:property 
value="#mediaFile.name"/>"
+                                     data-mediafile-url="<s:property 
value="%{mediaFileURL}"/>"
+                                     data-mediafile-is-image="<s:property 
value="#mediaFile.isImageFile()"/>">
 
                                     <s:if test="#mediaFile.imageFile">
-                                        <img border="0" src='<s:property 
value="%{mediaFileThumbnailURL}" />'
-                                             width='<s:property 
value="#mediaFile.thumbnailWidth"/>'
-                                             height='<s:property 
value="#mediaFile.thumbnailHeight"/>'
-                                             alt='<s:property 
value="#mediaFile.name" />'/>
+                                        <img border="0" src="<s:property 
value='%{mediaFileThumbnailURL}' />"
+                                             width="<s:property 
value='#mediaFile.thumbnailWidth'/>"
+                                             height="<s:property 
value='#mediaFile.thumbnailHeight'/>"
+                                             alt="<s:property 
value='#mediaFile.name' />"/>
                                     </s:if>
 
                                     <s:else>
@@ -118,6 +118,13 @@
         window.parent.onSelectMediaFile(name, url, isImage);
     }
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.mediafile-select-target', function () {
+        onSelectMediaFile($(this).attr('data-mediafile-name'),
+                $(this).attr('data-mediafile-url'),
+                $(this).attr('data-mediafile-is-image'));
+    });
+
     function highlight(el, flag) {
         if (flag) {
             $(el).addClass("highlight");
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp
index 253220461..46a02002b 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp
@@ -19,7 +19,7 @@
 
 <s:form id="createPostForm" action='entryAddWithMediaFile'>
     <s:hidden name="salt"/>
-    <input type="hidden" name="weblog" value='<s:property 
value="actionWeblog.handle" />'/>
+    <input type="hidden" name="weblog" value="<s:property 
value='actionWeblog.handle' />"/>
     <input type="hidden" name="selectedImage" id="selectedImage"/>
     <input type="hidden" name="type" id="type"/>
 </s:form>
@@ -169,25 +169,25 @@
                             <li class="align-images"
                                 onmouseover="highlight(this, true)" 
onmouseout="highlight(this, false)">
 
-                                <div class="mediaObject" onclick="onClickEdit(
-                                        '<s:property value="#mediaFile.id"/>',
-                                        '<s:property 
value="#mediaFile.name"/>' )">
+                                <div class="mediaObject mediafile-edit-target"
+                                     data-mediafile-id="<s:property 
value="#mediaFile.id"/>"
+                                     data-mediafile-name="<s:property 
value="#mediaFile.name"/>">
 
                                     <s:if test="#mediaFile.imageFile">
-                                        <img border="0" src='<s:property 
value="%{#mediaFile.thumbnailURL}" />'
-                                             width='<s:property 
value="#mediaFile.thumbnailWidth" />'
-                                             height='<s:property 
value="#mediaFile.thumbnailHeight" />'
-                                             title='<s:property 
value="#mediaFile.name" />'
-                                             alt='<s:property 
value="#mediaFile.name" />'
-                                            <%-- 
onclick="onClickEdit('<s:property value="#mediaFile.id"/>')" --%> />
+                                        <img border="0" src="<s:property 
value='%{#mediaFile.thumbnailURL}' />"
+                                             width="<s:property 
value='#mediaFile.thumbnailWidth' />"
+                                             height="<s:property 
value='#mediaFile.thumbnailHeight' />"
+                                             title="<s:property 
value='#mediaFile.name' />"
+                                             alt="<s:property 
value='#mediaFile.name' />"
+                                            />
                                     </s:if>
 
                                     <s:else>
                                         <s:url var="mediaFileURL" 
value="/images/page.png"/>
-                                        <img border="0" src='<s:property 
value="%{mediaFileURL}" />'
+                                        <img border="0" src="<s:property 
value='%{mediaFileURL}' />"
                                              style="padding:40px 50px;"
-                                             alt='<s:property 
value="#mediaFile.name"/>'
-                                            <%-- 
onclick="onClickEdit('<s:property value="#mediaFile.id"/>')" --%> />
+                                             alt="<s:property 
value='#mediaFile.name'/>"
+                                            />
                                     </s:else>
 
                                 </div>
@@ -223,22 +223,22 @@
                             <li class="align-images"
                                 onmouseover="highlight(this, true)" 
onmouseout="highlight(this, false)">
 
-                                <div class="mediaObject" onclick="onClickEdit(
-                                        '<s:property value="#mediaFile.id"/>',
-                                        '<s:property 
value="#mediaFile.name"/>' )">
+                                <div class="mediaObject mediafile-edit-target"
+                                     data-mediafile-id="<s:property 
value="#mediaFile.id"/>"
+                                     data-mediafile-name="<s:property 
value="#mediaFile.name"/>">
 
                                     <s:if test="#mediaFile.imageFile">
-                                        <img border="0" src='<s:property 
value="%{#mediaFile.thumbnailURL}" />'
-                                             width='<s:property 
value="#mediaFile.thumbnailWidth"/>'
-                                             height='<s:property 
value="#mediaFile.thumbnailHeight"/>'
-                                             title='<s:property 
value="#mediaFile.name" />'
-                                             alt='<s:property 
value="#mediaFile.name"/>'/>
+                                        <img border="0" src="<s:property 
value='%{#mediaFile.thumbnailURL}' />"
+                                             width="<s:property 
value='#mediaFile.thumbnailWidth'/>"
+                                             height="<s:property 
value='#mediaFile.thumbnailHeight'/>"
+                                             title="<s:property 
value='#mediaFile.name' />"
+                                             alt="<s:property 
value='#mediaFile.name'/>"/>
                                     </s:if>
 
                                     <s:else>
                                         <s:url var="mediaFileURL" 
value="/images/page.png"/>
-                                        <img border="0" src='<s:property 
value="%{mediaFileURL}" />'
-                                             style="padding:40px 50px;" 
alt='<s:property value="#mediaFile.name"/>'/>
+                                        <img border="0" src="<s:property 
value='%{mediaFileURL}' />"
+                                             style="padding:40px 50px;" 
alt="<s:property value='#mediaFile.name'/>"/>
                                     </s:else>
 
                                 </div>
@@ -348,11 +348,17 @@
         <s:url var="mediaFileEditURL" action="mediaFileEdit">
         <s:param name="weblog" value="%{actionWeblog.handle}" />
         </s:url>
-        $('#edit-subtitle').html(mediaFileName);
+        $('#edit-subtitle').text(mediaFileName);
         $('#mediaFileEditor').attr('src', '<s:property 
value="%{mediaFileEditURL}" />' + '&mediaFileId=' + mediaFileId);
         $('#mediafile_edit_lightbox').modal({show: true});
     }
 
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.mediafile-edit-target', function () {
+        onClickEdit($(this).attr('data-mediafile-id'),
+                $(this).attr('data-mediafile-name'));
+    });
+
     function onEditSuccess() {
         onEditCancelled();
         document.mediaFileViewForm.submit();
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
index 4b738d3f8..81b10e642 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
@@ -177,11 +177,19 @@
 </s:form>
 
 
+<div id="template-edit-data" style="display:none"
+     data-weblog-url="<s:property value="actionWeblog.absoluteURL" />"
+     data-original-link="<s:property value="bean.link" />"
+     data-template-type="<s:property value="bean.type" />"></div>
+
 <script type="text/javascript">
 
-    var weblogURL = '<s:property value="actionWeblog.absoluteURL" />';
-    var originalLink = '<s:property value="bean.link" />';
-    var type = '<s:property value="bean.type" />';
+    // Read from escaped data attributes rather than generated string
+    // literals; the template link is author-supplied.
+    var templateData = $('#template-edit-data');
+    var weblogURL = templateData.attr('data-weblog-url');
+    var originalLink = templateData.attr('data-original-link');
+    var type = templateData.attr('data-template-type');
 
     $(document).ready(function () {
 
@@ -199,7 +207,7 @@
         if (link !== "") {
             $("#no_link").hide();
             $("#good_link").show();
-            $("#linkPreview").html(link);
+            $("#linkPreview").text(link);
         } else {
             $("#good_link").hide();
             $("#no_link").show();
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
index 05bd6cb1f..d5e36ac0d 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/Templates.jsp
@@ -73,8 +73,9 @@
                                 <s:param name="weblog" 
value="actionWeblog.handle"/>
                                 <s:param name="removeId" value="#p.id"/>
                             </s:url>
-                            <a href="#" onclick=
-                                    "confirmTemplateDelete('<s:property 
value="#p.id"/>', '<s:property value="#p.name"/>' )">
+                            <a href="#" class="template-delete-link"
+                               data-template-id="<s:property value="#p.id"/>"
+                               data-template-name="<s:property 
value="#p.name"/>">
                                 <span class="glyphicon glyphicon-trash"></span>
                             </a>
 
@@ -107,4 +108,11 @@
             document.getElementById("templates").submit();
         }
     }
+
+    // Values come from data-* attributes and are bound via delegated 
listeners.
+    $(document).on('click', '.template-delete-link', function (event) {
+        event.preventDefault();
+        confirmTemplateDelete($(this).attr('data-template-id'),
+                $(this).attr('data-template-name'));
+    });
 </script>
diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp 
b/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
index dac1ec885..f71d9de08 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
@@ -246,7 +246,7 @@
         $.ajax({
             url: "<s:url value='themedata'/>",
             data: {theme: themeId}, success: function (data) {
-                $('#themeDescription').html(data.description);
+                $('#themeDescription').text(data.description);
                 thumbnail = $('#themeThumbnail');
                 thumbnail.attr('src', '<s:property value="siteURL" />' + 
data.previewPath);
             }
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/AuthoringUiSinkAuditTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/AuthoringUiSinkAuditTest.java
new file mode 100644
index 000000000..cf8eac734
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/AuthoringUiSinkAuditTest.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.  For additional
+ * information regarding copyright in this work, please see the NOTICE
+ * file in the top level directory of this distribution.
+ */
+package org.apache.roller.weblogger.ui.struts2.editor;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * Structural audit of the authoring UI templates.
+ *
+ * <p>Values that originate from weblog content are rendered by the editor 
JSPs.
+ * This test enforces the two structural rules that keep those values inert: 
they
+ * travel in double-quoted <code>data-*</code> attributes rather than inline
+ * handler literals, and they are written to the DOM through a text API. It is 
a
+ * source audit rather than a behavioural test because the guarantee is a
+ * property of the whole page family, not of any one code path.
+ */
+public class AuthoringUiSinkAuditTest {
+
+    private static final Path JSP_ROOT = Paths.get(
+            System.getProperty("project.basedir", 
System.getProperty("user.dir")),
+            "src", "main", "webapp", "WEB-INF", "jsps");
+
+    /**
+     * An inline event handler attribute whose body opens a single-quoted
+     * JavaScript string containing a Struts property. Newlines are collapsed
+     * before matching because these handlers routinely wrap across lines.
+     */
+    private static final Pattern HANDLER_LITERAL =
+            Pattern.compile("on[a-zA-Z]+\\s*=\\s*\"[^\"]*'\\s*<s:property");
+
+    /** A bare JavaScript variable assignment from a Struts property. */
+    private static final Pattern SCRIPT_VAR_LITERAL =
+            Pattern.compile("var\\s+\\w+\\s*=\\s*'\\s*<s:property");
+
+    /**
+     * A jQuery html() write. Calls passing only a localized string, an empty
+     * string, or nothing are inert and are excluded.
+     */
+    private static final Pattern HTML_WRITE =
+            
Pattern.compile("\\.html\\(\\s*(?!\\)|''|\"\"|'<s:text|\"<s:text|\"<textarea|cdata\\.content|comments\\[id\\])[^)]");
+
+    /**
+     * The comment moderation screen has a separate round-trip for its already
+     * encoded editing markup; this audit focuses on authoring values inserted
+     * directly from Struts properties or response descriptions.
+     */
+    private List<Path> editorJsps() throws IOException {
+        Path editor = JSP_ROOT.resolve("editor");
+        Path core = JSP_ROOT.resolve("core");
+        assertTrue(Files.isDirectory(editor), "cannot locate editor JSPs at " 
+ editor);
+        assertTrue(Files.isDirectory(core), "cannot locate core JSPs at " + 
core);
+        try (Stream<Path> files = Stream.concat(Files.list(editor), 
Files.list(core))) {
+            return files.filter(p -> 
p.getFileName().toString().endsWith(".jsp"))
+                    .sorted().collect(Collectors.toList());
+        }
+    }
+
+    private List<String> findMatches(Pattern pattern) throws IOException {
+        List<String> offenders = new ArrayList<>();
+        for (Path jsp : editorJsps()) {
+            String body = new String(Files.readAllBytes(jsp), 
StandardCharsets.UTF_8);
+            Matcher matcher = pattern.matcher(body);
+            while (matcher.find()) {
+                String snippet = matcher.group().replaceAll("\\s+", " 
").trim();
+                offenders.add(jsp.getFileName() + ": " + snippet);
+            }
+        }
+        return offenders;
+    }
+
+    /**
+     * No weblog-controlled value may sit inside a single-quoted JavaScript
+     * string literal in an inline event handler. An apostrophe in the value
+     * closes the literal and the rest of the value is parsed as code.
+     */
+    @Test
+    public void noStrutsPropertyInsideInlineHandlerLiteral() throws 
IOException {
+        List<String> offenders = findMatches(HANDLER_LITERAL);
+        assertTrue(offenders.isEmpty(),
+                "authoring values must travel in data-* attributes, not inline 
"
+                        + "handler string literals; found " + offenders.size() 
+ ":\n  "
+                        + String.join("\n  ", offenders));
+    }
+
+    /**
+     * The same rule for values assigned into script variables, which are the
+     * non-handler form of the identical defect.
+     */
+    @Test
+    public void noStrutsPropertyInsideScriptVariableLiteral() throws 
IOException {
+        List<String> offenders = findMatches(SCRIPT_VAR_LITERAL);
+        assertTrue(offenders.isEmpty(),
+                "authoring values must reach script through data-* attributes, 
"
+                        + "not single-quoted var initialisers; found " + 
offenders.size() + ":\n  "
+                        + String.join("\n  ", offenders));
+    }
+
+    /**
+     * No dynamic value may be written to the DOM as markup. Moving a value 
into
+     * a data attribute does not help if a later html() call re-parses it.
+     */
+    @Test
+    public void noDynamicHtmlWrites() throws IOException {
+        List<String> offenders = findMatches(HTML_WRITE);
+        assertTrue(offenders.isEmpty(),
+                "dynamic values must be written with a text API (.text(), "
+                        + ".val(), textContent) rather than .html(); found "
+                        + offenders.size() + ":\n  " + String.join("\n  ", 
offenders));
+    }
+
+    /**
+     * Guards the audit itself: if the JSP directory moved or the patterns 
stopped
+     * matching anything at all, the three tests above would pass vacuously.
+     */
+    @Test
+    public void auditActuallyInspectsTheEditorTemplates() throws IOException {
+        List<Path> jsps = editorJsps();
+        assertFalse(jsps.isEmpty(), "audit found no editor JSPs to inspect");
+        assertTrue(jsps.size() >= 10,
+                "expected the editor template family, found only " + 
jsps.size());
+    }
+}

Reply via email to