tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http ServerCookie.java
Date Fri, 03 Dec 2004 18:12:07 GMT
luehe       2004/12/03 10:12:07

  Modified:    util/java/org/apache/tomcat/util/http ServerCookie.java
  Log:
  Escape any double quotes in Version 1 cookies
  
  Revision  Changes    Path
  1.8       +27 -1     jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/ServerCookie.java
  
  Index: ServerCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/ServerCookie.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ServerCookie.java	14 Oct 2004 22:53:14 -0000	1.7
  +++ ServerCookie.java	3 Dec 2004 18:12:07 -0000	1.8
  @@ -278,7 +278,7 @@
               buf.append(value);
           } else {
               buf.append('"');
  -            buf.append(value);
  +            buf.append(escapeDoubleQuotes(value));
               buf.append('"');
           }
       }
  @@ -288,6 +288,32 @@
       public static void log(String s ) {
           if (log.isDebugEnabled())
               log.debug("ServerCookie: " + s);
  +    }
  +
  +
  +    /**
  +     * Escapes any double quotes in the given string.
  +     *
  +     * @param s the input string
  +     *
  +     * @return The (possibly) escaped string
  +     */
  +    private static String escapeDoubleQuotes(String s) {
  +
  +        if (s == null || s.length() == 0 || s.indexOf('"') == -1) {
  +            return s;
  +        }
  +
  +        StringBuffer b = new StringBuffer();
  +        for (int i = 0; i < s.length(); i++) {
  +            char c = s.charAt(i);
  +            if (c == '"')
  +                b.append('\\').append('"');
  +            else
  +                b.append(c);
  +        }
  +
  +        return b.toString();
       }
   
   }
  
  
  

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


Mime
View raw message