@Test public void testDecodingInvalidValuesWithCommaAtStart() { assertNull(ClientCookieDecoder.STRICT.decode(",")); assertNull(ClientCookieDecoder.STRICT.decode(",a")); assertNull(ClientCookieDecoder.STRICT.decode(",a=a")); }
public Cookie decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return null; } CookieBuilder cookieBuilder = null; loop: for (int i = 0;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == ',') { break loop; } else if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') { valueEnd--; } if (cookieBuilder == null) { DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie == null) { return null; } cookieBuilder = new CookieBuilder(cookie, header); } else { cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd); } } return cookieBuilder != null ? cookieBuilder.cookie() : null; }
ClientCookieDecoder extends CookieDecoder { public Cookie decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return null; } CookieBuilder cookieBuilder = null; loop: for (int i = 0;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == ',') { break loop; } else if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') { valueEnd--; } if (cookieBuilder == null) { DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie == null) { return null; } cookieBuilder = new CookieBuilder(cookie, header); } else { cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd); } } return cookieBuilder != null ? cookieBuilder.cookie() : null; } }
ClientCookieDecoder extends CookieDecoder { public Cookie decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return null; } CookieBuilder cookieBuilder = null; loop: for (int i = 0;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == ',') { break loop; } else if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') { valueEnd--; } if (cookieBuilder == null) { DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie == null) { return null; } cookieBuilder = new CookieBuilder(cookie, header); } else { cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd); } } return cookieBuilder != null ? cookieBuilder.cookie() : null; } private  ClientCookieDecoder(boolean strict); }
ClientCookieDecoder extends CookieDecoder { public Cookie decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return null; } CookieBuilder cookieBuilder = null; loop: for (int i = 0;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == ',') { break loop; } else if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') { valueEnd--; } if (cookieBuilder == null) { DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie == null) { return null; } cookieBuilder = new CookieBuilder(cookie, header); } else { cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd); } } return cookieBuilder != null ? cookieBuilder.cookie() : null; } private  ClientCookieDecoder(boolean strict); Cookie decode(String header); }
ClientCookieDecoder extends CookieDecoder { public Cookie decode(String header) { final int headerLen = checkNotNull(header, "header").length(); if (headerLen == 0) { return null; } CookieBuilder cookieBuilder = null; loop: for (int i = 0;;) { for (;;) { if (i == headerLen) { break loop; } char c = header.charAt(i); if (c == ',') { break loop; } else if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header.charAt(i); if (curChar == ';') { nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { nameEnd = i; i++; if (i == headerLen) { valueBegin = valueEnd = 0; break; } valueBegin = i; int semiPos = header.indexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') { valueEnd--; } if (cookieBuilder == null) { DefaultCookie cookie = initCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie == null) { return null; } cookieBuilder = new CookieBuilder(cookie, header); } else { cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd); } } return cookieBuilder != null ? cookieBuilder.cookie() : null; } private  ClientCookieDecoder(boolean strict); Cookie decode(String header); static final ClientCookieDecoder STRICT; static final ClientCookieDecoder LAX; }