Skip to content

Commit bb61a4b

Browse files
authored
Set domain_to_ascii be_strict argument to false (#37)
* Set be_strict flag in domain_to_ascii to false, updated tests * Applied be_strict to domain_to_ascii overload * Check host, hostname and port in unit test
1 parent 6219432 commit bb61a4b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

include/skyr/unicode/domain.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ tl::expected<std::string, std::error_code> punycode_decode(
6666
/// \returns An ASCII domain, or an error
6767
tl::expected<std::string, std::error_code> domain_to_ascii(
6868
std::string_view domain,
69-
bool be_strict = true);
69+
bool be_strict = false);
7070

7171
/// Converts a UTF-32 encoded domain to ASCII using
7272
/// [IDNA processing](https://www.unicode.org/reports/tr46/#Processing)
@@ -76,7 +76,7 @@ tl::expected<std::string, std::error_code> domain_to_ascii(
7676
/// \returns An ASCII domain, or an error
7777
tl::expected<std::string, std::error_code> domain_to_ascii(
7878
std::u32string_view domain,
79-
bool be_strict = true);
79+
bool be_strict = false);
8080
} // namespace unicode
8181
} // namespace v1
8282
} // namespace skyr

tests/unicode/domain_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ TEST_CASE("valid domains", "[domain]") {
3131
TEST_CASE("invalid domains", "[domain]") {
3232
SECTION("invalid_domain_1") {
3333
auto instance = skyr::unicode::domain_to_ascii("GOO  goo.com");
34+
REQUIRE(instance);
35+
}
36+
37+
SECTION("invalid_domain_1_be strict") {
38+
auto instance = skyr::unicode::domain_to_ascii("GOO  goo.com", true);
3439
REQUIRE_FALSE(instance);
3540
}
3641

@@ -46,6 +51,11 @@ TEST_CASE("invalid domains", "[domain]") {
4651

4752
SECTION("invalid_domain_4") {
4853
auto instance = skyr::unicode::domain_to_ascii("%41.com");
54+
REQUIRE(instance);
55+
}
56+
57+
SECTION("invalid_domain_4_be strict") {
58+
auto instance = skyr::unicode::domain_to_ascii("%41.com", true);
4959
REQUIRE_FALSE(instance);
5060
}
5161
}

tests/url/url_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,4 +566,14 @@ TEST_CASE("url_tests", "[url]") {
566566
CHECK("example.com" == instance.host());
567567
CHECK("?a=b&c=d" == instance.search());
568568
}
569+
570+
SECTION("domain_to_ascii_be_strict_issue_36")
571+
{
572+
auto instance = skyr::url("https://+:80/vroot/");
573+
CHECK("https:" == instance.protocol());
574+
CHECK("+:80" == instance.host());
575+
CHECK("+" == instance.hostname());
576+
CHECK("80" == instance.port());
577+
CHECK("/vroot/" == instance.pathname());
578+
}
569579
}

0 commit comments

Comments
 (0)