Skip to content

Commit b4e9b2c

Browse files
committed
Strip ipv6 brackets in CreateFromUri
1 parent 4017c57 commit b4e9b2c

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

source/io/Socks5ProxyOptions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
#include <climits>
1010
#include <utility>
1111

12+
namespace {
13+
Aws::Crt::String s_NormalizeProxyHostLiteral(const Aws::Crt::String &host) {
14+
if (host.length() >= 2 && host.front() == '[' && host.back() == ']') {
15+
return host.substr(1, host.length() - 2);
16+
}
17+
return host;
18+
}
19+
} // namespace
20+
1221
namespace Aws
1322
{
1423
namespace Crt
@@ -343,6 +352,7 @@ namespace Aws
343352
}
344353

345354
String host(reinterpret_cast<const char *>(hostCursor.ptr), hostCursor.len);
355+
host = s_NormalizeProxyHostLiteral(host);
346356

347357
uint32_t port = uri.GetPort();
348358
if (port == 0)

tests/Socks5ProxyOptionsTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ static int s_TestSocks5ProxyOptionsCreateFromUriAuth(struct aws_allocator *alloc
8080
}
8181
AWS_TEST_CASE(Socks5ProxyOptionsCreateFromUriAuth, s_TestSocks5ProxyOptionsCreateFromUriAuth)
8282

83+
static int s_TestSocks5ProxyOptionsCreateFromUriIpv6Literal(struct aws_allocator *allocator, void *)
84+
{
85+
ApiHandle apiHandle(allocator);
86+
87+
const char *proxyUri = "socks5://[::1]:1080";
88+
Uri uri(aws_byte_cursor_from_c_str(proxyUri), allocator);
89+
ASSERT_TRUE(uri);
90+
91+
auto options = Socks5ProxyOptions::CreateFromUri(uri, 1000, allocator);
92+
ASSERT_TRUE(options.has_value());
93+
94+
const aws_socks5_proxy_options *raw = options->GetUnderlyingHandle();
95+
ASSERT_NOT_NULL(raw);
96+
ASSERT_NOT_NULL(raw->host);
97+
ASSERT_STR_EQUALS("::1", aws_string_c_str(raw->host));
98+
ASSERT_INT_EQUALS(1080, raw->port);
99+
100+
return AWS_OP_SUCCESS;
101+
}
102+
AWS_TEST_CASE(Socks5ProxyOptionsCreateFromUriIpv6Literal, s_TestSocks5ProxyOptionsCreateFromUriIpv6Literal)
103+
83104
static int s_TestSocks5ProxyOptionsCreateFromUriInvalid(struct aws_allocator *allocator, void *)
84105
{
85106
ApiHandle apiHandle(allocator);

0 commit comments

Comments
 (0)