You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/11/22 00:40:17 UTC
[3/3] mesos git commit: Added an optional `additional_chars`
parameter to `http::encode`.
Added an optional `additional_chars` parameter to `http::encode`.
The new `additional_chars` parameter specifies the extra characters to
be percent-encoded, in addition to the ones specified in RFC 3986.
Review: https://reviews.apache.org/r/62635/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0842dd70
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0842dd70
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0842dd70
Branch: refs/heads/master
Commit: 0842dd70c5e75636d9ac964e90638d4108060b1d
Parents: 138e5c0
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
Authored: Tue Nov 21 16:08:46 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 21 16:33:51 2017 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/http.hpp | 15 ++++++++++++---
3rdparty/libprocess/src/http.cpp | 6 ++++--
3rdparty/libprocess/src/tests/http_tests.cpp | 10 ++++++++++
3 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0842dd70/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 78cf2c3..055447e 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -885,9 +885,18 @@ Try<hashmap<std::string, std::string>> parse(
} // namespace path {
-// Returns a percent-encoded string according to RFC 3986.
-// The input string must not already be percent encoded.
-std::string encode(const std::string& s);
+/**
+ * Returns a percent-encoded string according to RFC 3986.
+ * @see <a href="https://tools.ietf.org/html/rfc3986#section-2.3">RFC3986</a>
+ *
+ * @param s The input string, must not arleady be percent-encoded.
+ * @param additional_chars When specified, all characters in it are also
+ * percent-encoded.
+ * @return The percent-encoded string of `s`.
+ */
+std::string encode(
+ const std::string& s,
+ const std::string& additional_chars = "");
// Decodes a percent-encoded string according to RFC 3986.
http://git-wip-us.apache.org/repos/asf/mesos/blob/0842dd70/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index 0cecb28..f51d2aa 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -740,7 +740,7 @@ Try<hashmap<string, string>> parse(const string& pattern, const string& path)
} // namespace path {
-string encode(const string& s)
+string encode(const string& s, const string& additional_chars)
{
ostringstream out;
@@ -780,7 +780,9 @@ string encode(const string& s)
default:
// ASCII control characters and non-ASCII characters.
// NOTE: The cast to unsigned int is needed.
- if (c < 0x20 || c > 0x7F) {
+ if (c < 0x20 ||
+ c > 0x7F ||
+ additional_chars.find_first_of(c) != string::npos) {
out << '%' << std::setfill('0') << std::setw(2) << std::hex
<< std::uppercase << (unsigned int) c;
} else {
http://git-wip-us.apache.org/repos/asf/mesos/blob/0842dd70/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 3190ca3..9daac71 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -598,6 +598,16 @@ TEST_P(HTTPTest, Encode)
}
+TEST_P(HTTPTest, EncodeAdditionalChars)
+{
+ string unencoded = "foo.bar";
+ string encoded = http::encode(unencoded, ".");
+
+ EXPECT_EQ("foo%2Ebar", encoded);
+ EXPECT_SOME_EQ(unencoded, http::decode(encoded));
+}
+
+
TEST_P(HTTPTest, PathParse)
{
const string pattern = "/books/{isbn}/chapters/{chapter}";