From a26d1e4392777f38d1fe7e84c514469b97e4b70a Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 13 Mar 2009 12:48:23 +0000 Subject: [PATCH] Fixed a problem where CookieDecoder doesn't strip surrounding quotes for certain values --- .../netty/handler/codec/http/CookieDecoder.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/CookieDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/CookieDecoder.java index ed838cef8b..529a6c08ce 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/CookieDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/CookieDecoder.java @@ -95,6 +95,7 @@ public class CookieDecoder { comment = QueryStringDecoder.decodeComponent(value, charset); } else if (CookieHeaderNames.COMMENTURL.equalsIgnoreCase(name)) { + value = trimSurroundingQuotes(value); commentURL = QueryStringDecoder.decodeComponent(value, charset); } else if (CookieHeaderNames.DOMAIN.equalsIgnoreCase(name)) { @@ -113,6 +114,7 @@ public class CookieDecoder { version = Integer.valueOf(value); } else if (CookieHeaderNames.PORT.equalsIgnoreCase(name)) { + value = trimSurroundingQuotes(value); String[] portList = value.split(COMMA); ports = new int[portList.length]; for (int i1 = 0; i1 < portList.length; i1++) { @@ -144,4 +146,17 @@ public class CookieDecoder { } return cookies; } + + private String trimSurroundingQuotes(String value) { + if (value.length() >= 2) { + char firstChar = value.charAt(0); + char lastChar = value.charAt(value.length() - 1); + if ((firstChar == '"' || firstChar == '\'') && + (lastChar == '"' || lastChar == '\'')) { + // Strip surrounding quotes. + value = value.substring(1, value.length() - 1); + } + } + return value; + } }