Chromium Code Reviews| Index: net/cookies/parsed_cookie.cc |
| diff --git a/net/cookies/parsed_cookie.cc b/net/cookies/parsed_cookie.cc |
| index 2175692f534a0ff8c4db3a65f898858a47da8a10..e3fe4031dd287fb87a507b475ef5c1ffa20fde3e 100644 |
| --- a/net/cookies/parsed_cookie.cc |
| +++ b/net/cookies/parsed_cookie.cc |
| @@ -363,14 +363,21 @@ void ParsedCookie::ParseTokenValuePairs(const std::string& cookie_line) { |
| // Then we can log any unexpected terminators. |
| std::string::const_iterator end = FindFirstTerminator(cookie_line); |
| + // For an empty |cookie_line|, add an empty-key with an empty value, which |
| + // has the effect of clearing any prior setting of the empty-key. This is done |
| + // to match the behavior of other browsers. See https://crbug.com/601786. |
| + if (it == end) |
| + pairs_.push_back(TokenValuePair("", "")); |
|
mmenke
2016/08/15 21:11:03
Maybe add an early return? Doesn't make a differe
jww
2016/08/16 02:24:23
Early return sgtm. Done.
|
| + |
| for (int pair_num = 0; pair_num < kMaxPairs && it != end; ++pair_num) { |
| TokenValuePair pair; |
| std::string::const_iterator token_start, token_end; |
| - if (!ParseToken(&it, end, &token_start, &token_end)) |
| + bool did_parse_token = ParseToken(&it, end, &token_start, &token_end); |
| + if (!did_parse_token && pair_num != 0) |
|
mmenke
2016/08/15 21:11:03
Think this is worth a comment (Just "Allow first t
mmenke
2016/08/15 21:11:03
What about if other tokens are empty? Do other br
jww
2016/08/16 02:24:23
Comment added.
For tokens other than the first, I
mmenke
2016/08/16 15:06:47
Ahh...The "break;" was concerning me. I had assum
|
| break; |
| - if (it == end || *it != '=') { |
| + if (!did_parse_token || it == end || *it != '=') { |
| // We have a token-value, we didn't have any token name. |
| if (pair_num == 0) { |
| // For the first time around, we want to treat single values |
| @@ -380,7 +387,7 @@ void ParsedCookie::ParseTokenValuePairs(const std::string& cookie_line) { |
| pair.first = ""; |
| // Rewind to the beginning of what we thought was the token name, |
| // and let it get parsed as a value. |
| - it = token_start; |
| + it = did_parse_token ? token_start : start; |
|
mmenke
2016/08/15 21:11:03
Having this extra logic seems a little ugly.
I'd
jww
2016/08/16 02:24:23
I agree that this is ugly, but from looking at thi
|
| } else { |
| // Any not-first attribute we want to treat a value as a |
| // name with an empty value... This is so something like |
| @@ -421,17 +428,11 @@ void ParsedCookie::ParseTokenValuePairs(const std::string& cookie_line) { |
| } |
| void ParsedCookie::SetupAttributes() { |
| - // Ignore Set-Cookie directive where name and value are both empty. |
| - if (pairs_[0].first.empty() && pairs_[0].second.empty()) { |
| - pairs_.clear(); |
| - return; |
| - } |
| - |
| // We skip over the first token/value, the user supplied one. |
| for (size_t i = 1; i < pairs_.size(); ++i) { |
| if (pairs_[i].first == kPathTokenName) { |
| path_index_ = i; |
| - } else if (pairs_[i].first == kDomainTokenName) { |
| + } else if (pairs_[i].first == kDomainTokenName && pairs_[i].second != "") { |
|
mmenke
2016/08/15 21:11:03
Here's something weird:
For all the other tokens,
jww
2016/08/16 02:24:23
This wouldn't match the other UAs, unfortunately,
mmenke
2016/08/16 15:06:47
Sorry, should have been clearer. Looking at this
|
| domain_index_ = i; |
| } else if (pairs_[i].first == kExpiresTokenName) { |
| expires_index_ = i; |