From 38314b519154bbef81a89939fd403d2e8d018175 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 2 Jun 2012 23:05:20 -0700 Subject: [PATCH] Fix #378 again - @jroper's fix did not work, so I just fixed it again. Conflicts: src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java --- .../handler/codec/http/CookieDecoder.java | 3 +- .../handler/codec/http/DefaultCookie.java | 57 +++++++++++-------- .../handler/codec/http/CookieDecoderTest.java | 2 + 3 files changed, 38 insertions(+), 24 deletions(-) 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 6a8c6749b1..cf0d1201fe 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 @@ -113,7 +113,6 @@ public class CookieDecoder { } Cookie c = new DefaultCookie(name, value); - cookies.add(c); boolean discard = false; boolean secure = false; @@ -189,6 +188,8 @@ public class CookieDecoder { c.setPorts(ports); c.setDiscard(discard); } + + cookies.add(c); } return cookies; diff --git a/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java b/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java index 38da9c770e..b183a9c106 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/DefaultCookie.java @@ -247,22 +247,24 @@ public class DefaultCookie implements Cookie { return false; } - if (getPath() == null && that.getPath() != null) { + if (getPath() == null) { + if (that.getPath() != null) { + return false; + } + } else if (that.getPath() == null) { return false; - } else if (that.getPath() == null && getPath() != null) { - return false; - } - if (!getPath().equals(that.getPath())) { + } else if (!getPath().equals(that.getPath())) { return false; } - if (getDomain() == null && that.getDomain() != null) { - return false; - } else if (that.getDomain() == null && getDomain() != null) { - return false; - } - if (!getDomain().equalsIgnoreCase(that.getDomain())) { + if (getDomain() == null) { + if (that.getDomain() != null) { + return false; + } + } else if (that.getDomain() == null) { return false; + } else { + return getDomain().equalsIgnoreCase(that.getDomain()); } return true; @@ -275,23 +277,31 @@ public class DefaultCookie implements Cookie { return v; } - if (getPath() == null && c.getPath() != null) { - return -1; - } else if (c.getPath() == null && getPath() != null) { + if (getPath() == null) { + if (c.getPath() != null) { + return -1; + } + } else if (c.getPath() == null) { return 1; + } else { + v = getPath().compareTo(c.getPath()); + if (v != 0) { + return v; + } } - v = getPath().compareTo(c.getPath()); - if (v != 0) { + + if (getDomain() == null) { + if (c.getDomain() != null) { + return -1; + } + } else if (c.getDomain() == null) { + return 1; + } else { + v = getDomain().compareToIgnoreCase(c.getDomain()); return v; } - if (getDomain() == null && c.getDomain() != null) { - return -1; - } else if (c.getDomain() == null && getDomain() != null) { - return 1; - } - v = getDomain().compareToIgnoreCase(c.getDomain()); - return v; + return 0; } @Override @@ -346,3 +356,4 @@ public class DefaultCookie implements Cookie { return value; } } + diff --git a/src/test/java/org/jboss/netty/handler/codec/http/CookieDecoderTest.java b/src/test/java/org/jboss/netty/handler/codec/http/CookieDecoderTest.java index a5470a4ecc..d418826e32 100644 --- a/src/test/java/org/jboss/netty/handler/codec/http/CookieDecoderTest.java +++ b/src/test/java/org/jboss/netty/handler/codec/http/CookieDecoderTest.java @@ -233,6 +233,7 @@ public class CookieDecoderTest { Iterator it = cookies.iterator(); Cookie c; + assertTrue(it.hasNext()); c = it.next(); assertEquals(1, c.getVersion()); assertEquals("session_id", c.getName()); @@ -244,6 +245,7 @@ public class CookieDecoderTest { assertTrue(c.getPorts().isEmpty()); assertEquals(-1, c.getMaxAge()); + assertTrue(it.hasNext()); c = it.next(); assertEquals(1, c.getVersion()); assertEquals("session_id", c.getName());