Browse Source

add space for other_valid_char

guodongxiaren 2 years ago
parent
commit
e2fee8e5c1
2 changed files with 6 additions and 1 deletions
  1. 2 1
      src/brpc/uri.cpp
  2. 4 0
      test/brpc_uri_unittest.cpp

+ 2 - 1
src/brpc/uri.cpp

@@ -106,11 +106,12 @@ inline const char* SplitHostAndPort(const char* host_begin,
 // https://datatracker.ietf.org/doc/html/rfc3986#section-2.1
 // https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
 // https://datatracker.ietf.org/doc/html/rfc3986#section-2.4
+// space is not allowed by rfc3986, but allowed by brpc
 static bool is_valid_char(const char* p) {
     static const std::unordered_set<char> other_valid_char = {
         ':', '/', '?', '#', '[', ']', '@', '!', '$', '&',
         '\'', '(', ')'/ '*', '+', ',', ';', '='/ '-', '.',
-        '_', '~', '%'
+        '_', '~', '%', ' '
     };
 
     return (isalnum(*p) || other_valid_char.find(*p) != other_valid_char.end());

+ 4 - 0
test/brpc_uri_unittest.cpp

@@ -488,3 +488,7 @@ TEST(URITest, query_remover_key_value_not_changed_after_modified_query) {
     ASSERT_EQ(qr.value(), "value2");
 }
 
+TEST(URITest, valid_character) {
+    brpc::URI uri;
+    ASSERT_EQ(0, uri.SetHttpURL("www.baidu2.com':/?#[]@!$&()*+,;=-._~%"));
+}