Skip to content

Commit

Permalink
reverted server string parsing behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Nov 30, 2023
1 parent dd769de commit 2a1c906
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ bool isLocalSocket(const char* host) {
return host[0] == '/';
}

// modifies input string and output pointers reference input
ServerSpec splitServerString(char* input) {
bool escaped = false;
ServerSpec res = { input, NULL, NULL };
for (;;input++) {
for (;; input++) {
switch (*input)
{
case '\0':
Expand All @@ -69,8 +70,12 @@ ServerSpec splitServerString(char* input) {
case ' ':
if (!escaped) {
*input = '\0';
res.alias = input + 1;
return res;
if (res.alias == NULL) {
res.alias = input + 1;
continue;
} else {
return res;
}
}
default:
escaped = false;
Expand Down
24 changes: 24 additions & 0 deletions tests/test_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ TEST(test_unix, host_parse_regression) {
ASSERT_STREQ(out.port, "21211");
ASSERT_STREQ(out.alias, "testing");
}

TEST(test_unix, socket_path_spaces) {
char test[] = "/tmp/spacey\\ path testing";
ServerSpec out = splitServerString(test);
ASSERT_STREQ(out.host, "/tmp/spacey\\ path");
ASSERT_EQ(out.port, nullptr);
ASSERT_STREQ(out.alias, "testing");
}

TEST(test_unix, socket_path_escaping) {
char test[] = "/tmp/spicy\\\\ path testing";
ServerSpec out = splitServerString(test);
ASSERT_STREQ(out.host, "/tmp/spicy\\\\");
ASSERT_EQ(out.port, nullptr);
ASSERT_STREQ(out.alias, "path");
}

TEST(test_unix, alias_space_escaping) {
char test[] = "/tmp/path testing\\ alias";
ServerSpec out = splitServerString(test);
ASSERT_STREQ(out.host, "/tmp/path");
ASSERT_EQ(out.port, nullptr);
ASSERT_STREQ(out.alias, "testing\\ alias");
}

0 comments on commit 2a1c906

Please sign in to comment.