OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cookies/cookie_util.h" | 5 #include "net/cookies/cookie_util.h" |
6 | 6 |
7 #include <cstdio> | 7 #include <cstdio> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 // Parse a cookie expiration time. We try to be lenient, but we need to | 86 // Parse a cookie expiration time. We try to be lenient, but we need to |
87 // assume some order to distinguish the fields. The basic rules: | 87 // assume some order to distinguish the fields. The basic rules: |
88 // - The month name must be present and prefix the first 3 letters of the | 88 // - The month name must be present and prefix the first 3 letters of the |
89 // full month name (jan for January, jun for June). | 89 // full month name (jan for January, jun for June). |
90 // - If the year is <= 2 digits, it must occur after the day of month. | 90 // - If the year is <= 2 digits, it must occur after the day of month. |
91 // - The time must be of the format hh:mm:ss. | 91 // - The time must be of the format hh:mm:ss. |
92 // An average cookie expiration will look something like this: | 92 // An average cookie expiration will look something like this: |
93 // Sat, 15-Apr-17 21:01:22 GMT | 93 // Sat, 15-Apr-17 21:01:22 GMT |
94 base::Time ParseCookieTime(const std::string& time_string) { | 94 base::Time ParseCookieTime(const std::string& time_string) { |
95 static const char* kMonths[] = { "jan", "feb", "mar", "apr", "may", "jun", | 95 static const char* const kMonths[] = { |
96 "jul", "aug", "sep", "oct", "nov", "dec" }; | 96 "jan", "feb", "mar", "apr", "may", "jun", |
| 97 "jul", "aug", "sep", "oct", "nov", "dec" }; |
97 static const int kMonthsLen = arraysize(kMonths); | 98 static const int kMonthsLen = arraysize(kMonths); |
98 // We want to be pretty liberal, and support most non-ascii and non-digit | 99 // We want to be pretty liberal, and support most non-ascii and non-digit |
99 // characters as a delimiter. We can't treat : as a delimiter, because it | 100 // characters as a delimiter. We can't treat : as a delimiter, because it |
100 // is the delimiter for hh:mm:ss, and we want to keep this field together. | 101 // is the delimiter for hh:mm:ss, and we want to keep this field together. |
101 // We make sure to include - and +, since they could prefix numbers. | 102 // We make sure to include - and +, since they could prefix numbers. |
102 // If the cookie attribute came in in quotes (ex expires="XXX"), the quotes | 103 // If the cookie attribute came in in quotes (ex expires="XXX"), the quotes |
103 // will be preserved, and we will get them here. So we make sure to include | 104 // will be preserved, and we will get them here. So we make sure to include |
104 // quote characters, and also \ for anything that was internally escaped. | 105 // quote characters, and also \ for anything that was internally escaped. |
105 static const char* kDelimiters = "\t !\"#$%&'()*+,-./;<=>?@[\\]^_`{|}~"; | 106 static const char kDelimiters[] = "\t !\"#$%&'()*+,-./;<=>?@[\\]^_`{|}~"; |
106 | 107 |
107 base::Time::Exploded exploded = {0}; | 108 base::Time::Exploded exploded = {0}; |
108 | 109 |
109 base::StringTokenizer tokenizer(time_string, kDelimiters); | 110 base::StringTokenizer tokenizer(time_string, kDelimiters); |
110 | 111 |
111 bool found_day_of_month = false; | 112 bool found_day_of_month = false; |
112 bool found_month = false; | 113 bool found_month = false; |
113 bool found_time = false; | 114 bool found_time = false; |
114 bool found_year = false; | 115 bool found_year = false; |
115 | 116 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 buffer.append(i->first.begin(), i->first.end()); | 261 buffer.append(i->first.begin(), i->first.end()); |
261 buffer.push_back('='); | 262 buffer.push_back('='); |
262 buffer.append(i->second.begin(), i->second.end()); | 263 buffer.append(i->second.begin(), i->second.end()); |
263 } | 264 } |
264 return buffer; | 265 return buffer; |
265 } | 266 } |
266 | 267 |
267 } // namespace cookie_utils | 268 } // namespace cookie_utils |
268 } // namespace net | 269 } // namespace net |
269 | 270 |
OLD | NEW |