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

Unified Diff: net/http/http_util.cc

Issue 1211363005: Parse HPKP report-uri and persist in TransportSecurityPersister (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetNext() fix Created 5 years, 5 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 | « net/http/http_util.h ('k') | net/http/http_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_util.cc
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index 9a88dad5c66ad1f5c6de4ad975d68fbdf02c9782..9abcfc8b798afa28b41e5011603de9dd757e202d 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -43,40 +43,6 @@ static size_t FindStringEnd(const std::string& line, size_t start, char delim) {
// HttpUtil -------------------------------------------------------------------
// static
-size_t HttpUtil::FindDelimiter(const std::string& line,
- size_t search_start,
- char delimiter) {
- do {
- // search_start points to the spot from which we should start looking
- // for the delimiter.
- const char delim_str[] = { delimiter, '"', '\'', '\0' };
- size_t cur_delim_pos = line.find_first_of(delim_str, search_start);
- if (cur_delim_pos == std::string::npos)
- return line.length();
-
- char ch = line[cur_delim_pos];
- if (ch == delimiter) {
- // Found delimiter
- return cur_delim_pos;
- }
-
- // We hit the start of a quoted string. Look for its end.
- search_start = FindStringEnd(line, cur_delim_pos, ch);
- if (search_start == line.length())
- return search_start;
-
- ++search_start;
-
- // search_start now points to the first char after the end of the
- // string, so just go back to the top of the loop and look for
- // |delimiter| again.
- } while (true);
-
- NOTREACHED();
- return line.length();
-}
-
-// static
void HttpUtil::ParseContentType(const std::string& content_type_str,
std::string* mime_type,
std::string* charset,
@@ -895,15 +861,22 @@ bool HttpUtil::ValuesIterator::GetNext() {
HttpUtil::NameValuePairsIterator::NameValuePairsIterator(
std::string::const_iterator begin,
std::string::const_iterator end,
- char delimiter)
+ char delimiter,
+ OptionalValues optional_values)
: props_(begin, end, delimiter),
valid_(true),
name_begin_(end),
name_end_(end),
value_begin_(end),
value_end_(end),
- value_is_quoted_(false) {
-}
+ value_is_quoted_(false),
+ values_optional_(optional_values == VALUES_OPTIONAL) {}
+
+HttpUtil::NameValuePairsIterator::NameValuePairsIterator(
+ std::string::const_iterator begin,
+ std::string::const_iterator end,
+ char delimiter)
+ : NameValuePairsIterator(begin, end, delimiter, VALUES_NOT_OPTIONAL) {}
HttpUtil::NameValuePairsIterator::~NameValuePairsIterator() {}
@@ -913,7 +886,7 @@ HttpUtil::NameValuePairsIterator::~NameValuePairsIterator() {}
// name='\'value\''
// name=value
// name = value
-// name=
+// name (if values_optional_ is true)
// Due to buggy implementations found in some embedded devices, we also
// accept values with missing close quotemark (http://crbug.com/39836):
// name="value
@@ -928,28 +901,34 @@ bool HttpUtil::NameValuePairsIterator::GetNext() {
// Scan for the equals sign.
std::string::const_iterator equals = std::find(value_begin_, value_end_, '=');
- if (equals == value_end_ || equals == value_begin_)
- return valid_ = false; // Malformed, no equals sign
-
- // Verify that the equals sign we found wasn't inside of quote marks.
- for (std::string::const_iterator it = value_begin_; it != equals; ++it) {
- if (HttpUtil::IsQuote(*it))
- return valid_ = false; // Malformed, quote appears before equals sign
+ if (equals == value_begin_)
+ return valid_ = false; // Malformed, no name
+ if (equals == value_end_ && !values_optional_)
+ return valid_ = false; // Malformed, no equals sign and values are required
+
+ // If an equals sign was found, verify that it wasn't inside of quote marks.
+ if (equals != value_end_) {
+ for (std::string::const_iterator it = value_begin_; it != equals; ++it) {
+ if (HttpUtil::IsQuote(*it))
+ return valid_ = false; // Malformed, quote appears before equals sign
+ }
}
name_begin_ = value_begin_;
name_end_ = equals;
- value_begin_ = equals + 1;
+ value_begin_ = (equals == value_end_) ? value_end_ : equals + 1;
TrimLWS(&name_begin_, &name_end_);
TrimLWS(&value_begin_, &value_end_);
value_is_quoted_ = false;
unquoted_value_.clear();
- if (value_begin_ == value_end_)
- return valid_ = false; // Malformed, value is empty
+ if (equals != value_end_ && value_begin_ == value_end_) {
+ // Malformed; value is empty
+ return valid_ = false;
+ }
- if (HttpUtil::IsQuote(*value_begin_)) {
+ if (value_begin_ != value_end_ && HttpUtil::IsQuote(*value_begin_)) {
// Trim surrounding quotemarks off the value
if (*value_begin_ != *(value_end_ - 1) || value_begin_ + 1 == value_end_) {
// NOTE: This is not as graceful as it sounds:
« no previous file with comments | « net/http/http_util.h ('k') | net/http/http_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698