This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new a810f2c54a Reduce code duplication a810f2c54a is described below commit a810f2c54a82ca0a7df8726fe5aa9abcdefb1e99 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed May 24 14:40:48 2023 +0100 Reduce code duplication --- java/org/apache/catalina/manager/JspHelper.java | 56 ++++++------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/java/org/apache/catalina/manager/JspHelper.java b/java/org/apache/catalina/manager/JspHelper.java index cb6db56572..bc0945c08f 100644 --- a/java/org/apache/catalina/manager/JspHelper.java +++ b/java/org/apache/catalina/manager/JspHelper.java @@ -24,6 +24,7 @@ import java.util.Locale; import org.apache.catalina.Session; import org.apache.catalina.manager.util.SessionUtils; +import org.apache.tomcat.util.security.Escape; /** @@ -191,57 +192,26 @@ public class JspHelper { } /** - * Performs the following substring replacements - * (to facilitate output to XML/HTML pages): + * Performs the following substring replacements (to facilitate output to XML/HTML pages): + * <ul> + * <li>& -> &amp;</li> + * <li>< -> &lt;</li> + * <li>> -> &gt;</li> + * <li>" -> &#034;</li> + * <li>' -> &#039;</li> + * </ul> * - * & -> &amp; - * < -> &lt; - * > -> &gt; - * " -> &#034; - * ' -> &#039; - * - * See also OutSupport.writeEscapedXml(). * @param buffer The XML to escape + * * @return the escaped XML */ - @SuppressWarnings("null") // escapedBuffer cannot be null public static String escapeXml(String buffer) { + if (buffer == null) { return ""; } - int start = 0; - int length = buffer.length(); - char[] arrayBuffer = buffer.toCharArray(); - StringBuilder escapedBuffer = null; - - for (int i = 0; i < length; i++) { - char c = arrayBuffer[i]; - if (c <= HIGHEST_SPECIAL) { - char[] escaped = specialCharactersRepresentation[c]; - if (escaped != null) { - // create StringBuilder to hold escaped xml string - if (start == 0) { - escapedBuffer = new StringBuilder(length + 5); - } - // add unescaped portion - if (start < i) { - escapedBuffer.append(arrayBuffer,start,i-start); - } - start = i + 1; - // add escaped xml - escapedBuffer.append(escaped); - } - } - } - // no xml escaping was necessary - if (start == 0) { - return buffer; - } - // add rest of unescaped portion - if (start < length) { - escapedBuffer.append(arrayBuffer,start,length-start); - } - return escapedBuffer.toString(); + + return Escape.xml(buffer); } public static String formatNumber(long number) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org