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

snoopdave pushed a commit to branch menu-weblog-description
in repository https://gitbox.apache.org/repos/asf/roller.git

commit f6668ba83fb371ce24576197385bd27dfae0c0ce
Author: David M. Johnson <[email protected]>
AuthorDate: Tue Oct 27 16:45:18 2026 -0400

    Drop an unclosed tag in removeHTML and print the weblog description as text 
on the main menu
---
 .../org/apache/roller/weblogger/util/Utilities.java  | 20 ++++++++++++++++++--
 app/src/main/webapp/WEB-INF/jsps/core/MainMenu.jsp   |  2 +-
 .../apache/roller/weblogger/util/UtilitiesTest.java  | 16 ++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java 
b/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
index f8a74602c..776419e72 100644
--- a/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
+++ b/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
@@ -183,9 +183,12 @@ public class Utilities {
                 start = endTag + 1;
                 beginTag = str.indexOf('<', start);
             }
-            // if no endTag found, get rest of str and break
+            // if no endTag found, the rest is text unless it starts a tag,
+            // which a browser would still parse as markup
             else {
-                ret.append(str.substring(beginTag));
+                if (!startsTag(str, beginTag)) {
+                    ret.append(str.substring(beginTag));
+                }
                 break;
             }
         }
@@ -196,6 +199,19 @@ public class Utilities {
         return ret.toString().trim();
     }
 
+    /**
+     * True if the '&lt;' at the given index opens a tag, comment or 
declaration,
+     * as browsers parse it: it is followed by a letter, '/', '!' or '?'.
+     */
+    private static boolean startsTag(String str, int index) {
+        if (index + 1 >= str.length()) {
+            return false;
+        }
+        char next = str.charAt(index + 1);
+        return (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z')
+                || next == '/' || next == '!' || next == '?';
+    }
+
     // ------------------------------------------------------------------------
     /**
      * Run both removeHTML and escapeHTML on a string.
diff --git a/app/src/main/webapp/WEB-INF/jsps/core/MainMenu.jsp 
b/app/src/main/webapp/WEB-INF/jsps/core/MainMenu.jsp
index d81dce008..c90f69006 100644
--- a/app/src/main/webapp/WEB-INF/jsps/core/MainMenu.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/core/MainMenu.jsp
@@ -71,7 +71,7 @@
             <p> <a href='<s:property value="#perms.weblog.absoluteURL" />'>
             <s:property value="#perms.weblog.absoluteURL" /></a></p>
 
-            <p><s:property value="#perms.weblog.about" escapeHtml="false" 
/></p>
+            <p><s:property value="#perms.weblog.about" /></p>
 
             <p>You have 
             <s:if test='#perms.hasAction("admin")'>ADMIN </s:if>
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/util/UtilitiesTest.java 
b/app/src/test/java/org/apache/roller/weblogger/util/UtilitiesTest.java
index 7e008aeb2..4d1ff1eb1 100644
--- a/app/src/test/java/org/apache/roller/weblogger/util/UtilitiesTest.java
+++ b/app/src/test/java/org/apache/roller/weblogger/util/UtilitiesTest.java
@@ -99,6 +99,22 @@ public class UtilitiesTest  {
         assertEquals(expect, result);
     }
 
+    @Test
+    public void testRemoveHTMLUnclosedTag() {
+        assertEquals("about", Utilities.removeHTML("about <img src=x", false));
+        assertEquals("about", Utilities.removeHTML("about <p>", false).trim());
+        assertEquals("a", Utilities.removeHTML("a </p", false));
+        assertEquals("a", Utilities.removeHTML("a <!-- note", false));
+        assertEquals("", Utilities.removeHTML("<img src=x", false));
+    }
+
+    @Test
+    public void testRemoveHTMLKeepsLessThanText() {
+        assertEquals("a < b", Utilities.removeHTML("a < b", false));
+        assertEquals("1 <2", Utilities.removeHTML("1 <2", false));
+        assertEquals("x <", Utilities.removeHTML("x <", false));
+    }
+
     @Test
     public void testTruncateNicely1() {
         String test = "blah blah blah blah blah";

Reply via email to