This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch entry-comments-link in repository https://gitbox.apache.org/repos/asf/roller.git
commit d8f17d233780ca674f58b1c920f64bfc6b643f2d Author: Matt Raible <[email protected]> AuthorDate: Wed Nov 25 15:47:00 2026 -0700 Keep the parameters of the Edit Entry comments link The sidebar's "Comments [n]" link is built with <s:url>, which writes "&" as "&", and is then passed to <s:text>, whose string arguments UIAction escapes again. The browser got "&" in the URL, so the weblog parameter was lost and the link ended on Permission Denied. The URL now uses escapeAmp="false", so it is escaped once, and JspOutputEncodingTest checks that a URL with more than one parameter isn't escaped twice. --- .../webapp/WEB-INF/jsps/editor/EntrySidebar.jsp | 2 +- .../ui/struts2/util/JspOutputEncodingTest.java | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp index 8080f6ab3..41bf6e269 100644 --- a/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp +++ b/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp @@ -29,7 +29,7 @@ <h3><s:text name="weblogEdit.comments" /></h3> <s:if test="bean.commentCount > 0"> - <s:url action="comments" var="commentsURL"> + <s:url action="comments" var="commentsURL" escapeAmp="false"> <s:param name="bean.entryId" value="bean.id" /> <s:param name="weblog" value="weblog" /> </s:url> diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java index 03438b753..af866f433 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java @@ -57,6 +57,8 @@ class JspOutputEncodingTest { Pattern.compile("<s:text\\b((?:[^>/]|/(?!>))*)>(.*?)</s:text>", Pattern.DOTALL); private static final Pattern SINGLE_QUOTED_ATTRIBUTE = Pattern.compile("[\\w:.-]+\\s*=\\s*'[^']*<s:property", Pattern.DOTALL); + private static final Pattern URL_WITH_BODY = + Pattern.compile("<s:url\\b((?:[^>/]|/(?!>))*)>(.*?)</s:url>", Pattern.DOTALL); private static final Pattern INLINE_HANDLER_PROPERTY = Pattern.compile("(?<![\\w:.-])on[a-z]+\\s*=\\s*\"[^\"]*<s:property", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); @@ -161,6 +163,38 @@ class JspOutputEncodingTest { assertEquals(Collections.emptyList(), problems); } + /** + * {@code <s:url>} writes "&" as "&" unless escapeAmp is false, and + * {@code <s:property>} and the {@code <s:param>} strings of an + * {@code <s:text>} escape it again. A link built that way reaches the + * browser with "&" in it and loses every parameter after the first. + */ + @Test + void urlsWithParamsAreNotEscapedTwice() throws IOException { + List<String> problems = new ArrayList<>(); + for (Path jsp : jsps) { + String text = read(jsp); + Matcher url = URL_WITH_BODY.matcher(text); + while (url.find()) { + Matcher var = Pattern.compile("\\bvar=\"([^\"]+)\"").matcher(url.group(1)); + if (!var.find() || url.group(1).contains("escapeAmp=\"false\"") + || url.group(2).split("<s:param\\b", -1).length < 3) { + continue; + } + Pattern use = Pattern.compile("<s:(property|param)\\b[^>]*value=[\"'](%\\{)?" + + Pattern.quote(var.group(1)) + "\\}?[\"'][^>]*>"); + Matcher written = use.matcher(text); + while (written.find()) { + if (!written.group().contains("escapeHtml=\"false\"")) { + problems.add(name(jsp) + ": " + var.group(1)); + break; + } + } + } + } + assertEquals(Collections.emptyList(), problems); + } + private static String read(Path jsp) throws IOException { return new String(Files.readAllBytes(jsp), StandardCharsets.UTF_8); }
