summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/engine/net/url_translator.cc2
-rw-r--r--net/base/escape.cc10
-rw-r--r--net/base/escape.h7
-rw-r--r--net/base/escape_unittest.cc15
4 files changed, 32 insertions, 2 deletions
diff --git a/chrome/browser/sync/engine/net/url_translator.cc b/chrome/browser/sync/engine/net/url_translator.cc
index 0931c36..a5943be 100644
--- a/chrome/browser/sync/engine/net/url_translator.cc
+++ b/chrome/browser/sync/engine/net/url_translator.cc
@@ -29,7 +29,7 @@ string CgiEscapeString(const char* src) {
}
string CgiEscapeString(const string& src) {
- return EscapePath(src);
+ return EscapeUrl(src);
}
// This method appends the query string to the sync server path.
diff --git a/net/base/escape.cc b/net/base/escape.cc
index f836afb6..18b2e0b 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -186,6 +186,16 @@ std::string EscapePath(const std::string& path) {
return Escape(path, kPathCharmap, false);
}
+// non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|}
+static const Charmap kUrlEscape(
+ 0xffffffffL, 0xf80008fdL, 0x78000001L, 0xb8000001L,
+ 0xffffffffL, 0xffffffffL, 0xffffffffL, 0xffffffffL
+);
+
+std::string EscapeUrl(const std::string& path) {
+ return Escape(path, kUrlEscape, true);
+}
+
// non-7bit
static const Charmap kNonASCIICharmap(
0x00000000L, 0x00000000L, 0x00000000L, 0x00000000L,
diff --git a/net/base/escape.h b/net/base/escape.h
index 17f8646..597755f 100644
--- a/net/base/escape.h
+++ b/net/base/escape.h
@@ -11,10 +11,15 @@
// Escaping --------------------------------------------------------------------
-// Escape a file or url path. This includes:
+// Escape a file. This includes:
// non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|}
std::string EscapePath(const std::string& path);
+// Escape an url. This includes:
+// non-printable, non-7bit, and (including space) ?>=<;+'&%$#"![\]^`{|}
+// Space is escaped as + and other special characters as %XX (hex).
+std::string EscapeUrl(const std::string& path);
+
// Escape all non-ASCII input.
std::string EscapeNonASCII(const std::string& input);
diff --git a/net/base/escape_unittest.cc b/net/base/escape_unittest.cc
index 8c31d41..6601edc 100644
--- a/net/base/escape_unittest.cc
+++ b/net/base/escape_unittest.cc
@@ -107,6 +107,21 @@ TEST(Escape, EscapePath) {
"%7B%7C%7D~%7F%80%FF");
}
+TEST(Escape, EscapeUrl) {
+ ASSERT_EQ(
+ // Most of the character space we care about, un-escaped
+ EscapeUrl(
+ "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;"
+ "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "[\\]^_`abcdefghijklmnopqrstuvwxyz"
+ "{|}~\x7f\x80\xff"),
+ // Escaped
+ "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B"
+ "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
+ "%7B%7C%7D~%7F%80%FF");
+}
+
TEST(Escape, UnescapeURLComponent) {
const UnescapeURLCase unescape_cases[] = {
{"", UnescapeRule::NORMAL, ""},