Author: markt
Date: Sun Mar  8 21:58:32 2015
New Revision: 1665085

URL: http://svn.apache.org/r1665085
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=57675
Correctly quote strings.

Added:
    
tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java   
(with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java

Modified: 
tomcat/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java?rev=1665085&r1=1665084&r2=1665085&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java 
Sun Mar  8 21:58:32 2015
@@ -141,16 +141,16 @@ public class ExtendedAccessLogValve exte
     // -------------------------------------------------------- Private Methods
 
     /**
-     *  Wrap the incoming value into quotes and escape any inner
-     *  quotes with double quotes.
+     * Wrap the incoming value with double quotes (") and escape any double
+     * quotes appearing in the value using two double quotes ("").
      *
-     *  @param value - The value to wrap quotes around
-     *  @return '-' if empty of null. Otherwise, toString() will
+     *  @param value - The value to wrap
+     *  @return '-' if null. Otherwise, toString() will
      *     be called on the object and the value will be wrapped
      *     in quotes and any quotes will be escaped with 2
      *     sets of quotes.
      */
-    private String wrap(Object value) {
+    static String wrap(Object value) {
         String svalue;
         // Does the value contain a " ? If so must encode it
         if (value == null || "-".equals(value)) {
@@ -159,32 +159,29 @@ public class ExtendedAccessLogValve exte
 
         try {
             svalue = value.toString();
-            if ("".equals(svalue)) {
-                return "-";
-            }
         } catch (Throwable e) {
             ExceptionUtils.handleThrowable(e);
             /* Log error */
             return "-";
         }
 
-        /* Wrap all quotes in double quotes. */
+        /* Wrap all values in double quotes. */
         StringBuilder buffer = new StringBuilder(svalue.length() + 2);
-        buffer.append('\'');
+        buffer.append('\"');
         int i = 0;
         while (i < svalue.length()) {
-            int j = svalue.indexOf('\'', i);
+            int j = svalue.indexOf('\"', i);
             if (j == -1) {
                 buffer.append(svalue.substring(i));
                 i = svalue.length();
             } else {
                 buffer.append(svalue.substring(i, j + 1));
                 buffer.append('"');
-                i = j + 2;
+                i = j + 1;
             }
         }
 
-        buffer.append('\'');
+        buffer.append('\"');
         return buffer.toString();
     }
 

Added: 
tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java?rev=1665085&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java 
(added)
+++ 
tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java 
Sun Mar  8 21:58:32 2015
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.catalina.valves;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestExtendedAccessLogValve {
+
+    @Test
+    public void alpha() {
+        Assert.assertEquals("\"foo\"", ExtendedAccessLogValve.wrap("foo"));
+    }
+
+    @Test
+    public void testNull() {
+        Assert.assertEquals("-", ExtendedAccessLogValve.wrap(null));
+    }
+
+    @Test
+    public void empty() {
+        Assert.assertEquals("\"\"", ExtendedAccessLogValve.wrap(""));
+    }
+
+    @Test
+    public void singleQuoteMiddle() {
+        Assert.assertEquals("\"foo'bar\"", 
ExtendedAccessLogValve.wrap("foo'bar"));
+    }
+
+    @Test
+    public void doubleQuoteMiddle() {
+        Assert.assertEquals("\"foo\"\"bar\"", 
ExtendedAccessLogValve.wrap("foo\"bar"));
+    }
+
+    @Test
+    public void doubleQuoteStart() {
+        Assert.assertEquals("\"\"\"foobar\"", 
ExtendedAccessLogValve.wrap("\"foobar"));
+    }
+
+    @Test
+    public void doubleQuoteEnd() {
+        Assert.assertEquals("\"foobar\"\"\"", 
ExtendedAccessLogValve.wrap("foobar\""));
+    }
+
+    @Test
+    public void doubleQuote() {
+        Assert.assertEquals("\"\"\"\"", ExtendedAccessLogValve.wrap("\""));
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/valves/TestExtendedAccessLogValve.java
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to