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

Unified Diff: net/base/escape.cc

Issue 646333002: Update EscapeExternalHandlerValue to keep '#', '[', and ']' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comments Created 6 years, 2 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
Index: net/base/escape.cc
diff --git a/net/base/escape.cc b/net/base/escape.cc
index 1798b6cae9a5ad73bc8891a31b8350558dff8e69..189a0c63d818f0bdf70468a0ff868e7810cf261d 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -39,15 +39,21 @@ struct Charmap {
// Given text to escape and a Charmap defining which values to escape,
// return an escaped string. If use_plus is true, spaces are converted
// 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) {
+// %20. And if keep_escaped is true, %XX will be kept as it is, otherwise, if
+// '%' is in the charmap, it is converted to %25.
+std::string Escape(const std::string& text,
+ const Charmap& charmap,
+ 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() &&
+ IsHexDigit(text[i + 1]) && IsHexDigit(text[i + 2])) {
+ escaped.push_back('%');
} else if (charmap.Contains(c)) {
escaped.push_back('%');
escaped.push_back(IntToHex(c >> 4));
@@ -293,9 +299,9 @@ static const Charmap kNonASCIICharmap = {{
}};
// Everything except alphanumerics, the reserved characters(;/?:@&=+$,) and
-// !'()*-._~%
+// !'()*-._~#[]
asanka 2014/10/23 07:20:04 Why remove '%'? Shouldn't we escape a % if it isn'
Jaekyun Seok (inactive) 2014/10/23 12:43:19 Yes. And so '%' should be removed because kExterna
static const Charmap kExternalHandlerCharmap = {{
- 0xffffffffL, 0x5000080dL, 0x68000000L, 0xb8000001L,
+ 0xffffffffL, 0x50000025L, 0x50000000L, 0xb8000001L,
0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
}};
@@ -318,7 +324,7 @@ std::string EscapeNonASCII(const std::string& input) {
}
std::string EscapeExternalHandlerValue(const std::string& text) {
- return Escape(text, kExternalHandlerCharmap, false);
+ return Escape(text, kExternalHandlerCharmap, false, true);
}
void AppendEscapedCharForHTML(char c, std::string* output) {

Powered by Google App Engine
This is Rietveld 408576698