Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/dns/idn_hostname_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,63 @@ TEST(DNS_idn_hostname, label_with_out_of_order_combining_marks_rejected) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("a\xcc\x81\xcc\x96"));
EXPECT_FALSE(sourcemeta::core::is_hostname("a\xcc\x81\xcc\x96"));
}

// --- additional coverage: subtle cases (whole-name Bidi, A-label
// re-validation, non-canonical Punycode, per-occurrence ContextJ) ---

// RFC 5893 sec 2: a digit-first label is invalid in a Bidi domain name
// (whole-name rule)
TEST(DNS_idn_hostname, invalid_bidi_digit_first_in_bidi_domain) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x30\x61\x2e\xd7\x90"));
}

// RFC 5893 sec 2 cond 1: label must start with L, R or AL
TEST(DNS_idn_hostname, invalid_bidi_single_label_digit_then_rtl) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x30\xd8\xa7"));
}
Comment on lines +602 to +609

// RFC 5893 sec 2 cond 5: an LTR label may not contain an RTL letter
TEST(DNS_idn_hostname, invalid_bidi_ltr_label_with_rtl_letter) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x61\xd7\x90"));
}

// RFC 5890 sec 2.3.2.1 + 5892 sec 2.6: decodes to U+00A1 (DISALLOWED)
TEST(DNS_idn_hostname, invalid_a_label_decodes_to_disallowed) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x78\x6e\x2d\x2d\x37\x61"));

@augmentcode augmentcode Bot Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These A-label cases are pure ASCII; since is_hostname() also re-validates xn-- labels via idna_is_valid_a_label, consider asserting EXPECT_FALSE(sourcemeta::core::is_hostname(...)) here as well to pin behavior for the ASCII-only API.

Severity: low

Other Locations
  • test/dns/idn_hostname_test.cc:622
  • test/dns/idn_hostname_test.cc:627
  • test/dns/idn_hostname_test.cc:632

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This A-label is pure ASCII and is_hostname() also validates xn-- labels. Add a corresponding EXPECT_FALSE(sourcemeta::core::is_hostname(...)) assertion here (and for the other A-label tests at lines 622, 627, 632) to pin behavior for the ASCII-only validation path consistently with the pattern used elsewhere in this file.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/dns/idn_hostname_test.cc, line 617:

<comment>This A-label is pure ASCII and `is_hostname()` also validates `xn--` labels. Add a corresponding `EXPECT_FALSE(sourcemeta::core::is_hostname(...))` assertion here (and for the other A-label tests at lines 622, 627, 632) to pin behavior for the ASCII-only validation path consistently with the pattern used elsewhere in this file.</comment>

<file context>
@@ -593,3 +593,56 @@ TEST(DNS_idn_hostname, label_with_out_of_order_combining_marks_rejected) {
+
+// RFC 5890 sec 2.3.2.1 + 5892 sec 2.6: decodes to U+00A1 (DISALLOWED)
+TEST(DNS_idn_hostname, invalid_a_label_decodes_to_disallowed) {
+  EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x78\x6e\x2d\x2d\x37\x61"));
+}
+
</file context>

}

// RFC 5890 sec 2.3.2.1: A-label decodes to the all-ASCII label example
TEST(DNS_idn_hostname, invalid_a_label_decodes_to_ascii_only) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname(
"\x78\x6e\x2d\x2d\x65\x78\x61\x6d\x70\x6c\x65\x2d"));
}

// RFC 5890 sec 2.3.2.1 + 5893: decodes to a-grave + Hebrew aleph
TEST(DNS_idn_hostname, invalid_a_label_decodes_to_bidi_violation) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname(
"\x78\x6e\x2d\x2d\x30\x63\x61\x32\x34\x77"));
}

// RFC 5891 sec 5.4: non-canonical Punycode; canonical form is xn--9uc
TEST(DNS_idn_hostname, invalid_noncanonical_punycode) {
EXPECT_FALSE(
sourcemeta::core::is_idn_hostname("\x78\x6e\x2d\x2d\x2d\x39\x75\x63"));
}
Comment on lines +634 to +637

// RFC 5892 sec 2.6: fullwidth digits U+FF11..U+FF13 are DISALLOWED
TEST(DNS_idn_hostname, invalid_fullwidth_digits) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname(
"\xef\xbc\x91\xef\xbc\x92\xef\xbc\x93"));
}

// RFC 5892 sec 2.6: U+200B (ZERO WIDTH SPACE) is DISALLOWED
TEST(DNS_idn_hostname, invalid_zero_width_space) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname("\x61\xe2\x80\x8b\x62"));
}
Comment on lines +646 to +648

// RFC 5892 appendix A.1 (errata 3312): the ZWNJ rule must hold at every
// occurrence
TEST(DNS_idn_hostname, invalid_zwnj_failing_at_one_occurrence) {
EXPECT_FALSE(sourcemeta::core::is_idn_hostname(
"\xe0\xa4\x95\xe0\xa5\x8d\xe2\x80\x8c\xe0\xa4\xb7\x78\xe2\x80\x8c\x79"));
}
Loading