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

Unified Diff: net/cookies/canonical_cookie.cc

Issue 1746303002: Replace std::string::find with base::StartsWith when comparing cookie paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove new test case Created 4 years, 10 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
« no previous file with comments | « no previous file | net/cookies/cookie_monster.cc » ('j') | net/cookies/cookie_monster.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/canonical_cookie.cc
diff --git a/net/cookies/canonical_cookie.cc b/net/cookies/canonical_cookie.cc
index fff3fa44b928cf95f2052cef60c7a1f4ca3cc753..0a5e794fe81cdbea370de2ad45c467d900707fbe 100644
--- a/net/cookies/canonical_cookie.cc
+++ b/net/cookies/canonical_cookie.cc
@@ -47,6 +47,7 @@
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
@@ -349,15 +350,14 @@ bool CanonicalCookie::IsOnPath(const std::string& url_path) const {
// was longer, the same length, or shorter than the length of the url path.
// I think the approach below is simpler.
- // Make sure the cookie path is a prefix of the url path. If the
- // url path is shorter than the cookie path, then the cookie path
- // can't be a prefix.
- if (url_path.find(path_) != 0)
+ // Make sure the cookie path is a prefix of the url path. If the url path is
+ // shorter than the cookie path, then the cookie path can't be a prefix.
+ if (!base::StartsWith(url_path, path_, base::CompareCase::SENSITIVE))
mmenke 2016/03/02 20:02:01 Does this really mean that you can set cookies wit
Mike West 2016/03/03 18:56:28 That sounds wrong. The path matching algorithm at
mmenke 2016/03/03 19:02:58 Sorry, that should be "/bar/" and "/bar"... and w
return false;
- // Now we know that url_path is >= cookie_path, and that cookie_path
- // is a prefix of url_path. If they are the are the same length then
- // they are identical, otherwise we need an additional check:
+ // |url_path| is >= |path_|, and |path_| is a prefix of |url_path|. If they
+ // are the are the same length then they are identical, otherwise need an
+ // additional check:
// In order to avoid in correctly matching a cookie path of /blah
// with a request path of '/blahblah/', we need to make sure that either
@@ -365,8 +365,9 @@ bool CanonicalCookie::IsOnPath(const std::string& url_path) const {
// in the url path. Since we know that the url path length is greater
// than the cookie path length, it's safe to index one byte past.
if (path_.length() != url_path.length() && path_.back() != '/' &&
- url_path[path_.length()] != '/')
+ url_path[path_.length()] != '/') {
return false;
+ }
return true;
}
« no previous file with comments | « no previous file | net/cookies/cookie_monster.cc » ('j') | net/cookies/cookie_monster.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698