Index: net/http/http_util.h |
diff --git a/net/http/http_util.h b/net/http/http_util.h |
index 458a7187441a253e2ad862785fb076824f1643c6..34e82fe853a1aeb3026e0ea2080e7cffeb9a2d5e 100644 |
--- a/net/http/http_util.h |
+++ b/net/http/http_util.h |
@@ -134,6 +134,18 @@ class NET_EXPORT HttpUtil { |
// Same as above. |
static std::string Unquote(const std::string& str); |
+ // Similar to Unquote(), but additionally validates that the string being |
+ // unescaped actually is a valid quoted string. Returns false for an empty |
mmenke
2016/04/26 18:05:58
Think we should mention this still allows single q
Marijn Kruisselbrink
2016/04/27 01:49:49
Done
|
+ // string, a string without quotes, a string with mismatched quotes, and |
+ // a string with unescaped embeded quotes. |
+ static bool StrictUnquote(std::string::const_iterator begin, |
+ std::string::const_iterator end, |
+ std::string* out) WARN_UNUSED_RESULT; |
mmenke
2016/04/26 18:05:58
nit: Include "base/macros.h" for WARN_UNUSED_RESU
Marijn Kruisselbrink
2016/04/27 01:49:49
Done
|
+ |
+ // Same as above. |
+ static bool StrictUnquote(const std::string& str, |
+ std::string* out) WARN_UNUSED_RESULT; |
+ |
// The reverse of Unquote() -- escapes and surrounds with " |
static std::string Quote(const std::string& str); |
@@ -332,18 +344,26 @@ class NET_EXPORT HttpUtil { |
// calls to GetNext() or after the NameValuePairsIterator is destroyed. |
class NET_EXPORT NameValuePairsIterator { |
public: |
- // Whether or not values are optional. VALUES_OPTIONAL allows |
- // e.g. name1=value1;name2;name3=value3, whereas VALUES_NOT_OPTIONAL |
+ // Whether or not values are optional. Values::OPTIONAL allows |
+ // e.g. name1=value1;name2;name3=value3, whereas Vaues::NOT_OPTIONAL |
// will treat it as a parse error because name2 does not have a |
// corresponding equals sign. |
- enum OptionalValues { VALUES_OPTIONAL, VALUES_NOT_OPTIONAL }; |
+ enum class Values { OPTIONAL, NOT_OPTIONAL }; |
+ |
+ // Whether or not unmatched quotes should be considered a failure. By |
+ // default this class is pretty lenient and does a best effort to parse |
+ // values with mismatched quotes. When set to STRICT a value with |
+ // mismatched or otherwise invalid quotes is considered a parse error. |
+ enum class Quotes { STRICT, NOT_STRICT }; |
NameValuePairsIterator(std::string::const_iterator begin, |
std::string::const_iterator end, |
char delimiter, |
- OptionalValues optional_values); |
+ Values optional_values, |
+ Quotes strict_quotes); |
- // Treats values as not optional by default (VALUES_NOT_OPTIONAL). |
+ // Treats values as not optional by default (Values::NOT_OPTIONAL) and |
+ // treats quotes as not strict. |
NameValuePairsIterator(std::string::const_iterator begin, |
std::string::const_iterator end, |
char delimiter); |
@@ -403,6 +423,11 @@ class NET_EXPORT HttpUtil { |
// True if values are required for each name/value pair; false if a |
// name is permitted to appear without a corresponding value. |
bool values_optional_; |
+ |
+ // True if quotes values are required to be properly quoted; false if |
+ // mismatched quotes and other problems with quoted values should be more |
+ // or less gracefully treated as valid. |
+ bool strict_quotes_; |
}; |
}; |