Skip to content

Disallow a single dot in IDN hostnames #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
return FormatValidator.Invalid()
}
if (value.length == 1 && isLabelSeparator(value[0])) {
return FormatValidator.Valid()
return FormatValidator.Invalid()
}

// https://datatracker.ietf.org/doc/html/rfc5893#section-1.4
Expand Down Expand Up @@ -506,6 +506,11 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
private fun isACE(label: String): Boolean =
label.length > Punycode.PREFIX_SIZE && label.startsWith(Punycode.PREFIX_STRING)

/**
* Returns `true` if the [c] is a dot
* according to [RFC3490 Section 3.1](https://datatracker.ietf.org/doc/html/rfc3490#section-3.1).
* Otherwise, returns `false`
*/
private fun isLabelSeparator(c: Char): Boolean = c == '.' || c == '\u3002' || c == '\uFF0E' || c == '\uFF61'

private fun findDot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class JsonSchemaIdnHostnameFormatValidationTest : FunSpec() {
format = "idn-hostname",
validTestCases =
listOf(
".",
"a",
"hostname",
// 63
Expand All @@ -30,6 +29,10 @@ class JsonSchemaIdnHostnameFormatValidationTest : FunSpec() {
invalidTestCases =
listOf(
TestCase("", "empty value"),
TestCase(".", "single separator"),
TestCase("\u3002", "single separator U+3002"),
TestCase("\uFF0E", "single separator U+FF0E"),
TestCase("\uFF61", "single separator U+FF61"),
TestCase("xn--80aakdqneodaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaai7g2bxc6qoj1f", "too long punycode"),
TestCase("оооооооооооооооооооооооооооооооооооченьдлиннаястрока", "too long unicode"),
// Not normalized \u4E3D. Example from https://unicode.org/Public/UNIDATA/NormalizationTest.txt
Expand Down
Loading