Skip to content

Commit d0cced9

Browse files
committed
Add DNS component support and update hostname validation
Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
1 parent d217b3b commit d0cced9

6 files changed

Lines changed: 7 additions & 8 deletions

File tree

.github/workflows/website-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
-DSOURCEMETA_CORE_CRYPTO:BOOL=OFF
3030
-DSOURCEMETA_CORE_REGEX:BOOL=OFF
3131
-DSOURCEMETA_CORE_IP:BOOL=OFF
32+
-DSOURCEMETA_CORE_DNS:BOOL=OFF
3233
-DSOURCEMETA_CORE_URI:BOOL=OFF
3334
-DSOURCEMETA_CORE_URITEMPLATE:BOOL=OFF
3435
-DSOURCEMETA_CORE_JSON:BOOL=OFF

.github/workflows/website-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
-DSOURCEMETA_CORE_CRYPTO:BOOL=OFF
4040
-DSOURCEMETA_CORE_REGEX:BOOL=OFF
4141
-DSOURCEMETA_CORE_IP:BOOL=OFF
42+
-DSOURCEMETA_CORE_DNS:BOOL=OFF
4243
-DSOURCEMETA_CORE_URI:BOOL=OFF
4344
-DSOURCEMETA_CORE_URITEMPLATE:BOOL=OFF
4445
-DSOURCEMETA_CORE_JSON:BOOL=OFF

config.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if(NOT SOURCEMETA_CORE_COMPONENTS)
1515
list(APPEND SOURCEMETA_CORE_COMPONENTS crypto)
1616
list(APPEND SOURCEMETA_CORE_COMPONENTS regex)
1717
list(APPEND SOURCEMETA_CORE_COMPONENTS ip)
18+
list(APPEND SOURCEMETA_CORE_COMPONENTS dns)
1819
list(APPEND SOURCEMETA_CORE_COMPONENTS uri)
1920
list(APPEND SOURCEMETA_CORE_COMPONENTS uritemplate)
2021
list(APPEND SOURCEMETA_CORE_COMPONENTS json)
@@ -61,6 +62,8 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS})
6162
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_regex.cmake")
6263
elseif(component STREQUAL "ip")
6364
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_ip.cmake")
65+
elseif(component STREQUAL "dns")
66+
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_dns.cmake")
6467
elseif(component STREQUAL "uri")
6568
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_ip.cmake")
6669
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uri.cmake")

src/core/dns/hostname.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ auto is_hostname(const std::string_view value) -> bool {
2929
std::string_view::size_type position{0};
3030

3131
while (position < value.size()) {
32-
// Start of a new label
3332
const auto label_start{position};
3433

3534
// RFC 1123 §2.1: first character is letter or digit
@@ -38,7 +37,6 @@ auto is_hostname(const std::string_view value) -> bool {
3837
}
3938
position += 1;
4039

41-
// Walk interior characters and the last character of the label
4240
while (position < value.size() && value[position] != '.') {
4341
// RFC 952 §B: interior characters are let-dig-hyp
4442
if (!is_let_dig_hyp(value[position])) {

src/core/dns/include/sourcemeta/core/dns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ namespace sourcemeta::core {
3636
/// ```
3737
///
3838
/// This function implements RFC 1123 §2.1 (ASCII only). It does not
39-
/// perform A-label or Punycode decoding — those belong to the separate
39+
/// perform A-label or Punycode decoding. Those belong to the separate
4040
/// `idn-hostname` format.
4141
SOURCEMETA_CORE_DNS_EXPORT
42-
auto is_hostname(std::string_view value) -> bool;
42+
auto is_hostname(const std::string_view value) -> bool;
4343

4444
} // namespace sourcemeta::core
4545

test/dns/hostname_test.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include <string>
66

7-
// VALID - RFC 1123 §2.1 / RFC 952 compliant inputs
8-
97
// RFC 952 §B: <hname> ::= <name>*["."<name>] (three labels, TS d7+ #7)
108
TEST(DNS_hostname, valid_simple_dotted) {
119
EXPECT_TRUE(sourcemeta::core::is_hostname("www.example.com"));
@@ -121,8 +119,6 @@ TEST(DNS_hostname, valid_many_labels) {
121119
EXPECT_TRUE(sourcemeta::core::is_hostname("a.b.c.d.e.f"));
122120
}
123121

124-
// INVALID - non-compliant inputs
125-
126122
// RFC 952 §B: <hname> requires at least one <name> / label (TS d7+ #12)
127123
TEST(DNS_hostname, invalid_empty) {
128124
EXPECT_FALSE(sourcemeta::core::is_hostname(""));

0 commit comments

Comments
 (0)