Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: net/cookies/canonical_cookie.cc

Issue 2898953008: Implement and test CanonicalCookie::IsCanonical() (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/cookies/canonical_cookie.cc
diff --git a/net/cookies/canonical_cookie.cc b/net/cookies/canonical_cookie.cc
index 6c81a55dc7df1d768618d9d76b338a0b0fd79974..949cb9da187651bc1e9bba3ddd1cd9803655c889 100644
--- a/net/cookies/canonical_cookie.cc
+++ b/net/cookies/canonical_cookie.cc
@@ -50,10 +50,12 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "net/base/url_util.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "url/gurl.h"
#include "url/url_canon.h"
+#include "url/url_util.h"
using base::Time;
using base::TimeDelta;
@@ -399,6 +401,29 @@ bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const {
return Priority() < other.Priority();
}
+bool CanonicalCookie::IsCanonical() const {
mmenke 2017/05/25 19:49:56 Is there a single method I should be comparing thi
Randy Smith (Not in Mondays) 2017/06/07 23:31:40 I modeled it after SetCookieWithDetails minus the
+ if (name_.empty())
mmenke 2017/05/25 19:49:56 Don't we support "Set-Cookie: =foo" and "Set-Cooki
mmenke 2017/05/25 21:25:21 Fun table that indicates we support both of these:
Randy Smith (Not in Mondays) 2017/06/07 23:31:40 Nice catch; my bad. This snuck in a couple of CLs
+ return false;
+
+ if (ParsedCookie::ParseTokenString(name_) != name_ ||
+ ParsedCookie::ParseValueString(value_) != value_ ||
+ ParsedCookie::ParseValueString(domain_) != domain_ ||
+ ParsedCookie::ParseValueString(path_) != path_) {
+ return false;
+ }
+
+ url::CanonHostInfo ignored;
+ if (!url::HostIsIPAddress(domain_) &&
+ CanonicalizeHost(domain_, &ignored).empty()) {
mmenke 2017/05/25 19:49:56 What if CanonicalizeHost(domain_) != domain_?
Randy Smith (Not in Mondays) 2017/06/07 23:31:40 Also note that the DCHECK(IsCanonical()) you sugge
Randy Smith (Not in Mondays) 2017/06/07 23:31:40 Oh, tricky. So as noted above I'm copying this lo
+ return false;
+ }
+
+ if (path_[0] != '/')
+ return false;
mmenke 2017/05/25 19:49:56 Do we always set path to be non-empty, even when n
Randy Smith (Not in Mondays) 2017/06/07 23:31:40 Yes, at least at a couple of places in the stack--
+
+ return true;
+}
+
// static
CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix(
const std::string& name) {

Powered by Google App Engine
This is Rietveld 408576698