diff --git a/src/Common.cpp b/src/Common.cpp index 15a85a1e..5d6f682f 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -57,12 +57,17 @@ bool isLocalSocket(const char* host) { } void verifyPort(const char* input, ServerSpec* res, bool* valid_port) { + /* if (*valid_port && input > res->port) { res->port[-1] = '\0'; } else if (res->alias == NULL) { res->port = NULL; } *valid_port = false; + */ + if (res->port != NULL) { + res->port[-1] = '\0'; + } } // modifies input string and output pointers reference input diff --git a/tests/test_unix.cpp b/tests/test_unix.cpp index 0c9979fc..bfc28342 100644 --- a/tests/test_unix.cpp +++ b/tests/test_unix.cpp @@ -34,6 +34,22 @@ TEST(test_unix, host_parse_regression) { ASSERT_STREQ(out.alias, "testing"); } +TEST(test_unix, host_parse_regression_tripped) { + char test[] = "127.0.0.1:21211 127.0.0.1:21211"; + ServerSpec out = splitServerString(test); + ASSERT_STREQ(out.host, "127.0.0.1"); + ASSERT_STREQ(out.port, "21211"); + ASSERT_STREQ(out.alias, "127.0.0.1:21211"); +} + +TEST(test_unix, tmpname) { + char test[] = "127.0.0.1:invalid_port"; + ServerSpec out = splitServerString(test); + ASSERT_STREQ(out.host, "127.0.0.1"); + ASSERT_STREQ(out.port, "invalid_port"); + ASSERT_EQ(out.alias, nullptr); +} + TEST(test_unix, socket_path_spaces) { char test[] = "/tmp/spacey\\ path testing"; ServerSpec out = splitServerString(test);