Author: remm Date: Thu Feb 21 15:22:42 2013 New Revision: 1448679 URL: http://svn.apache.org/r1448679 Log: String unescaping modifies the buffer used for the cookie, and will corrupt the original cookie header [visible when displaying them using getHeader]. Experiment with an option to preserve them. I don't think this should be the default, as it is almost never useful, and can be a bit wasteful.
Modified: tomcat/trunk/java/org/apache/tomcat/util/http/CookieSupport.java tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Modified: tomcat/trunk/java/org/apache/tomcat/util/http/CookieSupport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/CookieSupport.java?rev=1448679&r1=1448678&r2=1448679&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/CookieSupport.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/CookieSupport.java Thu Feb 21 15:22:42 2013 @@ -63,6 +63,12 @@ public final class CookieSupport { public static final boolean ALLOW_NAME_ONLY; /** + * If set to true, the cookie header will be preserved. In most cases + * except debugging, this is not useful. + */ + public static final boolean PRESERVE_COOKIE_HEADER; + + /** * The list of separators that apply to version 0 cookies. To quote the * spec, these are comma, semi-colon and white-space. The HTTP spec * definition of linear white space is [CRLF] 1*( SP | HT ) @@ -100,6 +106,15 @@ public final class CookieSupport { Boolean.valueOf(alwaysAddExpires).booleanValue(); } + String preserveCookieHeader = System.getProperty( + "org.apache.tomcat.util.http.ServerCookie.PRESERVE_COOKIE_HEADER"); + if (preserveCookieHeader == null) { + PRESERVE_COOKIE_HEADER = STRICT_SERVLET_COMPLIANCE; + } else { + PRESERVE_COOKIE_HEADER = + Boolean.valueOf(preserveCookieHeader).booleanValue(); + } + String fwdSlashIsSeparator = System.getProperty( "org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR"); if (fwdSlashIsSeparator == null) { Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java?rev=1448679&r1=1448678&r2=1448679&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Thu Feb 21 15:22:42 2013 @@ -165,9 +165,18 @@ public final class Cookies { log.debug("Cookies: Parsing b[]: " + cookieValue.toString()); } ByteChunk bc=cookieValue.getByteChunk(); - processCookieHeader( bc.getBytes(), - bc.getOffset(), - bc.getLength()); + if (CookieSupport.PRESERVE_COOKIE_HEADER) { + int len = bc.getLength(); + if (len > 0) { + byte[] buf = new byte[len]; + System.arraycopy(bc.getBytes(), bc.getOffset(), buf, 0, len); + processCookieHeader(buf, 0, len); + } + } else { + processCookieHeader( bc.getBytes(), + bc.getOffset(), + bc.getLength()); + } pos++;// search from the next position } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org