Skip to content

Commit 1090225

Browse files
authored
use crt cpp bindings for ipv6 (#3250)
1 parent cd009d5 commit 1090225

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/aws-cpp-sdk-core/source/utils/DNS.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <aws/core/utils/DNS.h>
77
#include <aws/core/utils/StringUtils.h>
8+
#include <aws/crt/DnsUtils.h>
89

910
namespace Aws
1011
{
@@ -49,7 +50,7 @@ namespace Aws
4950
return false;
5051
}
5152

52-
return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); });
53+
return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }) || Aws::Crt::DnsUtils::IsValidIpV6(host.c_str(), false);
5354
}
5455
}
5556
}

tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,29 @@ TEST_F(DnsTest, TestHost)
6161
ASSERT_FALSE(IsValidHost("0123456789012345678901234567890123456789012345678901234567890123.com")); // 64 characters
6262

6363
}
64+
65+
TEST_F(DnsTest, TestIPV6)
66+
{
67+
Aws::Vector< std::pair<Aws::String, bool> > inputs = {
68+
{"2001:0db8:85a3:0000:0000:8a2e:0370:7334", true},
69+
{"2001:DB8:85A3::8A2E:370:7334", true},
70+
{"::ffff", true},
71+
{"::", true},
72+
{"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",true},
73+
{"2001:db8:85a3:0:0:8a2e:370:7334",true},
74+
{"2001:db8:85a3:0000:0000:8a2e:0370:7334:1", false},
75+
{"2001:db8:85a3:0000", false},
76+
{"2001:0db8:85a3:0000:0000:8a2e:0370:7334:", false},
77+
{"g001:0db8:85a3:0000:0000:8a2e:0370:7334", false},
78+
{"2001:db8::85a3::1", false},
79+
{":2001:db8:85a3:0000:0000:8a2e:0370:7334", false},
80+
{"0:0:0:0:0:0:0:0", true},
81+
{"2001:db8::", true}
82+
};
83+
84+
for(auto t : inputs)
85+
{
86+
ASSERT_EQ(IsValidHost(t.first), t.second);
87+
}
88+
89+
}

0 commit comments

Comments
 (0)