Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change simple cookie header parse to keep most recently set #1835

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/jsoup/helper/HttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,8 @@ void processResponseHeaders(Map<String, List<String>> resHeaders) {
String cookieVal = cd.consumeTo(";").trim();
// ignores path, date, domain, validateTLSCertificates et al. full details will be available in cookiestore if required
// name not blank, value not null
if (cookieName.length() > 0 && !cookies.containsKey(cookieName)) // if duplicates, only keep the first
// If repeated, overwrite it with the latest one
if (!StringUtil.isBlank(cookieName))
cookie(cookieName, cookieVal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ private void doIt(HttpServletRequest req, HttpServletResponse res) throws IOExce
}

private void setCookies(HttpServletResponse res) {
Cookie one = new Cookie("One", "Root");
one.setPath("/");
res.addCookie(one);

// change order to pass the test
Cookie two = new Cookie("One", "CookieServlet");
two.setPath("/CookieServlet");
two.setHttpOnly(true);
Expand All @@ -71,6 +68,10 @@ private void setCookies(HttpServletResponse res) {
Cookie three = new Cookie("One", "EchoServlet");
three.setPath("/EchoServlet");
res.addCookie(three);

Cookie one = new Cookie("One", "Root");
one.setPath("/");
res.addCookie(one);
}

}