Skip to content

Commit

Permalink
Sort cookies by path length (longest first)
Browse files Browse the repository at this point in the history
* This makes sure the most specific cookies are sent first, matching
what other browsers do.
  • Loading branch information
pulkomandy committed Jun 6, 2014
1 parent 4e14963 commit 6ac7ba8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/kits/network/libnetapi/NetworkCookieJar.cpp
Expand Up @@ -160,7 +160,16 @@ BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
delete cookie;
} else {
TRACE("Add cookie: %s\n", cookie->RawCookie(true).String());
list->AddItem(cookie);
// Keep the list sorted by path length (longest first). This makes sure
// that cookies for most specific paths are returned first when
// iterating the cookie jar.
int32 i;
for (i = 0; i < list->CountItems(); i++) {
BNetworkCookie* current = list->ItemAt(i);
if (current->Path().Length() < cookie->Path().Length())
break;
}
list->AddItem(cookie, i);
}

return B_OK;
Expand Down

0 comments on commit 6ac7ba8

Please sign in to comment.