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

rjung 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 a326a53a9a Escape timestamp output in AccessLog.
a326a53a9a is described below

commit a326a53a9a132757dead071ce2159fdac9156c4f
Author: Rainer Jung <rainer.j...@kippdata.de>
AuthorDate: Thu Apr 27 09:31:33 2023 +0200

    Escape timestamp output in AccessLog.
    
    It is needed if a SimpleDateFormat is used which contains
    verbatim characters that need escaping.
---
 .../apache/catalina/valves/AbstractAccessLogValve.java | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java 
b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
index b947a912a5..c996948171 100644
--- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
+++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
@@ -1036,6 +1036,8 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
 
         /* Our format description string, null if CLF */
         private final String format;
+        /* Does the format string contain characters we need to escape */
+        private final boolean needsEscaping;
         /* Whether to use begin of request or end of response as the timestamp 
*/
         private final boolean usesBegin;
         /* The format type */
@@ -1074,6 +1076,16 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
 
         protected DateAndTimeElement(String sdf) {
             String format = sdf;
+            boolean needsEscaping = false;
+            if (sdf != null) {
+                CharArrayWriter writer = new CharArrayWriter();
+                escapeAndAppend(sdf, writer);
+                String escaped = writer.toString();
+                if (!escaped.equals(sdf)) {
+                    needsEscaping = true;
+                }
+            }
+            this.needsEscaping = needsEscaping;
             boolean usesBegin = false;
             FormatType type = FormatType.CLF;
 
@@ -1158,7 +1170,11 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                     temp = temp.replace(tripleMsecPattern, tripleMsec);
                     temp = temp.replace(msecPattern, Long.toString(frac));
                 }
-                buf.append(temp);
+                if (needsEscaping) {
+                    escapeAndAppend(temp, buf);
+                } else {
+                    buf.append(temp);
+                }
             }
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to