Skip to content

Commit 6b652e8

Browse files
authored
Disallow a single dot in IDN hostnames (#247)
Based on json-schema-org/JSON-Schema-Test-Suite#759 it is not allowed to have a single dot in the hostname (and IDN hostname). The hostname validator already had the correct behavior but the IDN hostname validator did not
1 parent 48fa0b4 commit 6b652e8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
4949
return FormatValidator.Invalid()
5050
}
5151
if (value.length == 1 && isLabelSeparator(value[0])) {
52-
return FormatValidator.Valid()
52+
return FormatValidator.Invalid()
5353
}
5454

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

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

511516
private fun findDot(

json-schema-validator/src/commonTest/kotlin/io/github/optimumcode/json/schema/assertions/general/format/JsonSchemaIdnHostnameFormatValidationTest.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class JsonSchemaIdnHostnameFormatValidationTest : FunSpec() {
99
format = "idn-hostname",
1010
validTestCases =
1111
listOf(
12-
".",
1312
"a",
1413
"hostname",
1514
// 63
@@ -30,6 +29,10 @@ class JsonSchemaIdnHostnameFormatValidationTest : FunSpec() {
3029
invalidTestCases =
3130
listOf(
3231
TestCase("", "empty value"),
32+
TestCase(".", "single separator"),
33+
TestCase("\u3002", "single separator U+3002"),
34+
TestCase("\uFF0E", "single separator U+FF0E"),
35+
TestCase("\uFF61", "single separator U+FF61"),
3336
TestCase("xn--80aakdqneodaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaai7g2bxc6qoj1f", "too long punycode"),
3437
TestCase("оооооооооооооооооооооооооооооооооооченьдлиннаястрока", "too long unicode"),
3538
// Not normalized \u4E3D. Example from https://unicode.org/Public/UNIDATA/NormalizationTest.txt

0 commit comments

Comments
 (0)