| Index: net/http/http_util.h
|
| diff --git a/net/http/http_util.h b/net/http/http_util.h
|
| index 458a7187441a253e2ad862785fb076824f1643c6..a2f7470284759b6214569c86c151b148a99d9ba9 100644
|
| --- a/net/http/http_util.h
|
| +++ b/net/http/http_util.h
|
| @@ -10,6 +10,7 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| +#include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/strings/string_tokenizer.h"
|
| #include "base/time/time.h"
|
| @@ -123,6 +124,13 @@ class NET_EXPORT HttpUtil {
|
| return IsToken(str.begin(), str.end());
|
| }
|
|
|
| + // Whether the string is a valid |parmname| as defined in RFC 5987 Sec 3.2.1.
|
| + static bool IsParmName(std::string::const_iterator begin,
|
| + std::string::const_iterator end);
|
| + static bool IsParmName(const std::string& str) {
|
| + return IsParmName(str.begin(), str.end());
|
| + }
|
| +
|
| // RFC 2616 Sec 2.2:
|
| // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
|
| // Unquote() strips the surrounding quotemarks off a string, and unescapes
|
| @@ -134,6 +142,20 @@ 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
|
| + // string, a string without quotes, a string with mismatched quotes, and
|
| + // a string with unescaped embeded quotes.
|
| + // Contrary to RFC 2616 this method does allow single quotes to enclose the
|
| + // string.
|
| + static bool StrictUnquote(std::string::const_iterator begin,
|
| + std::string::const_iterator end,
|
| + std::string* out) WARN_UNUSED_RESULT;
|
| +
|
| + // 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 +354,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 +433,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_;
|
| };
|
| };
|
|
|
|
|