| Index: net/base/escape.cc
|
| diff --git a/net/base/escape.cc b/net/base/escape.cc
|
| index ab70f1db30187e6a28e09757819d2f307291fd53..1844f64613ad4d715c0d3c7f97677d4c695403bd 100644
|
| --- a/net/base/escape.cc
|
| +++ b/net/base/escape.cc
|
| @@ -24,6 +24,13 @@ inline char IntToHex(int i) {
|
| return kHexString[i];
|
| }
|
|
|
| +inline bool IsHexChar(unsigned char c) {
|
| + if ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ||
|
| + (c >= '0' && c <= '9'))
|
| + return true;
|
| + return false;
|
| +}
|
| +
|
| // A fast bit-vector map for ascii characters.
|
| //
|
| // Internally stores 256 bits in an array of 8 ints.
|
| @@ -41,13 +48,17 @@ struct Charmap {
|
| // to +, otherwise, if spaces are in the charmap, they are converted to
|
| // %20.
|
| std::string Escape(const std::string& text, const Charmap& charmap,
|
| - bool use_plus) {
|
| + bool use_plus, bool keep_escaped = false) {
|
| std::string escaped;
|
| escaped.reserve(text.length() * 3);
|
| for (unsigned int i = 0; i < text.length(); ++i) {
|
| unsigned char c = static_cast<unsigned char>(text[i]);
|
| if (use_plus && ' ' == c) {
|
| escaped.push_back('+');
|
| + } else if (keep_escaped && '%' == c && i + 2 < text.length() &&
|
| + IsHexChar(static_cast<unsigned char>(text[i + 1])) &&
|
| + IsHexChar(static_cast<unsigned char>(text[i + 2]))) {
|
| + escaped.push_back('%');
|
| } else if (charmap.Contains(c)) {
|
| escaped.push_back('%');
|
| escaped.push_back(IntToHex(c >> 4));
|
| @@ -299,6 +310,13 @@ static const Charmap kExternalHandlerCharmap = {{
|
| 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
|
| }};
|
|
|
| +// Everything except alphanumerics, the reserved characters(;/?:@&=+$,), the
|
| +// mark characters(-_.!~*'()).
|
| +static const Charmap kQueryPartCharmap = {{
|
| + 0xffffffffL, 0x5000002dL, 0x78000000L, 0xb8000001L,
|
| + 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
|
| +}};
|
| +
|
| } // namespace
|
|
|
| std::string EscapeQueryParamValue(const std::string& text, bool use_plus) {
|
| @@ -321,6 +339,10 @@ std::string EscapeExternalHandlerValue(const std::string& text) {
|
| return Escape(text, kExternalHandlerCharmap, false);
|
| }
|
|
|
| +std::string EscapeQueryPart(const std::string& query) {
|
| + return Escape(query, kQueryPartCharmap, false, true);
|
| +}
|
| +
|
| void AppendEscapedCharForHTML(char c, std::string* output) {
|
| AppendEscapedCharForHTMLImpl(c, output);
|
| }
|
|
|