Repository: qpid-proton
Updated Branches:
  refs/heads/master 4dfe29692 -> d6cef7b8c


PROTON-1733: [cpp] fix proton::url to handle //... URLs

Previous implementation failed to parse URLs starting with "//" correctly.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c7fcec16
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c7fcec16
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c7fcec16

Branch: refs/heads/master
Commit: c7fcec16cf0f46a327828d80e81b6eb29d421a6b
Parents: 4dfe296
Author: Alan Conway <[email protected]>
Authored: Thu Jan 4 15:13:20 2018 -0500
Committer: Alan Conway <[email protected]>
Committed: Thu Jan 4 16:06:34 2018 -0500

----------------------------------------------------------------------
 proton-c/bindings/cpp/src/url.cpp      |  5 +-
 proton-c/bindings/cpp/src/url_test.cpp | 80 +++++++++++++++++++----------
 2 files changed, 57 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c7fcec16/proton-c/bindings/cpp/src/url.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/url.cpp 
b/proton-c/bindings/cpp/src/url.cpp
index 867f605..4ec0380 100644
--- a/proton-c/bindings/cpp/src/url.cpp
+++ b/proton-c/bindings/cpp/src/url.cpp
@@ -104,6 +104,9 @@ void parse_url(char *url, const char **scheme, const char 
**user, const char **p
       url = scheme_end + 3;
       slash = std::strchr(url, '/');
     }
+  } else if (0 == strncmp(url, "//", 2)) {
+      url += 2;
+      slash = std::strchr(url, '/');
   }
 
   if (slash) {
@@ -250,8 +253,6 @@ const std::string url::AMQP("amqp");
 const std::string url::AMQPS("amqps");
 
 uint16_t url::port_int() const {
-    // TODO aconway 2015-10-27: full service name lookup
-    // astitcher 2016-11-17: It is hard to make the full service name lookup 
platform independent
     if (port() == AMQP) return 5672;
     if (port() == AMQPS) return 5671;
     std::istringstream is(port());

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c7fcec16/proton-c/bindings/cpp/src/url_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/url_test.cpp 
b/proton-c/bindings/cpp/src/url_test.cpp
index 0727e2c..511c8d5 100644
--- a/proton-c/bindings/cpp/src/url_test.cpp
+++ b/proton-c/bindings/cpp/src/url_test.cpp
@@ -22,49 +22,77 @@
 
 namespace {
 
-void check_url(const std::string& s,
-               const std::string& scheme,
-               const std::string& user,
-               const std::string& pwd,
-               const std::string& host,
-               const std::string& port,
-               const std::string& path
-              )
-{
-    proton::url u(s);
-    ASSERT_EQUAL(scheme, u.scheme());
-    ASSERT_EQUAL(user, u.user());
-    ASSERT_EQUAL(pwd, u.password());
-    ASSERT_EQUAL(host, u.host());
-    ASSERT_EQUAL(port, u.port());
-    ASSERT_EQUAL(path, u.path());
-}
+#define CHECK_URL(S, SCHEME, USER, PWD, HOST, PORT, PATH) do {   \
+        proton::url u(S);                                        \
+        ASSERT_EQUAL(SCHEME, u.scheme());                        \
+        ASSERT_EQUAL(USER, u.user());                            \
+        ASSERT_EQUAL(PWD, u.password());                         \
+        ASSERT_EQUAL(HOST, u.host());                            \
+        ASSERT_EQUAL(PORT, u.port());                            \
+        ASSERT_EQUAL(PATH, u.path());                            \
+    } while(0)
 
 void parse_to_string_test() {
-    check_url("amqp://foo:xyz/path",
+    CHECK_URL("amqp://foo:xyz/path",
               "amqp", "", "", "foo", "xyz", "path");
-    check_url("amqp://username:password@host:1234/path",
+    CHECK_URL("amqp://username:password@host:1234/path",
               "amqp", "username", "password", "host", "1234", "path");
-    check_url("host:1234",
+    CHECK_URL("host:1234",
               "amqp", "", "", "host", "1234", "");
-    check_url("host",
+    CHECK_URL("host",
               "amqp", "", "", "host", "amqp", "");
-    check_url("host/path",
+    CHECK_URL("host/path",
               "amqp", "", "", "host", "amqp", "path");
-    check_url("amqps://host",
+    CHECK_URL("amqps://host",
               "amqps", "", "", "host", "amqps", "");
-    check_url("/path",
+    CHECK_URL("/path",
               "amqp", "", "", "localhost", "amqp", "path");
-    check_url("",
+    CHECK_URL("",
               "amqp", "", "", "localhost", "amqp", "");
-    check_url(":1234",
+    CHECK_URL(":1234",
               "amqp", "", "", "localhost", "1234", "");
 }
 
+void parse_slash_slash() {
+    CHECK_URL("//username:password@host:1234/path",
+              "amqp", "username", "password", "host", "1234", "path");
+    CHECK_URL("//host:port/path",
+              "amqp", "", "", "host", "port", "path");
+    CHECK_URL("//host",
+              "amqp", "", "", "host", "amqp", "");
+    CHECK_URL("//:port",
+              "amqp", "", "", "localhost", "port", "");
+    CHECK_URL("//:0",
+              "amqp", "", "", "localhost", "0", "");
+}
+
+#define CHECK_URL_NODEFAULT(S, SCHEME, USER, PWD, HOST, PORT, PATH) do {   \
+        proton::url u(S, false);                                        \
+        ASSERT_EQUAL(SCHEME, u.scheme());                               \
+        ASSERT_EQUAL(USER, u.user());                                   \
+        ASSERT_EQUAL(PWD, u.password());                                \
+        ASSERT_EQUAL(HOST, u.host());                                   \
+        ASSERT_EQUAL(PORT, u.port());                                   \
+        ASSERT_EQUAL(PATH, u.path());                                   \
+    } while(0)
+
+}
+
+void parse_nodefault() {
+    CHECK_URL_NODEFAULT("",
+                        "", "", "", "", "", "");
+    CHECK_URL_NODEFAULT("//:",
+                        "", "", "", "", "", "");
+    CHECK_URL_NODEFAULT("//:0",
+                        "", "", "", "", "0", "");
+    CHECK_URL_NODEFAULT("//h:",
+                        "", "", "", "h", "", "");
 }
 
 int main(int, char**) {
     int failed = 0;
     RUN_TEST(failed, parse_to_string_test());
+    RUN_TEST(failed, parse_slash_slash());
+    RUN_TEST(failed, parse_nodefault());
     return failed;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to