Skip to content

Commit 921581b

Browse files
committed
fix idn-hostname validation
1 parent 669bf35 commit 921581b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
4848
if (value.isEmpty()) {
4949
return FormatValidator.Invalid()
5050
}
51-
if (value.length == 1 && isLabelSeparator(value[0])) {
51+
if (isLabelSeparator(value[0]) || isLabelSeparator(value[value.lastIndex])) {
5252
return FormatValidator.Invalid()
5353
}
5454

@@ -113,6 +113,11 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
113113
return false
114114
}
115115

116+
if (unicode.isEmpty()) {
117+
// empty labels are not valid
118+
return false
119+
}
120+
116121
// https://datatracker.ietf.org/doc/html/rfc5891#section-4.2.3.1
117122
if (unicode[0] == '-' || unicode.codePointBefore(unicode.length) == '-'.code) {
118123
// cannot start or end with hyphen

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class JsonSchemaIdnHostnameFormatValidationTest : FunSpec() {
3333
listOf(
3434
TestCase("", "empty value"),
3535
TestCase(".", "single separator"),
36+
TestCase(".example", "leading separator"),
37+
TestCase("example.", "trailing separator"),
38+
TestCase("example..com", "two separators in a row"),
3639
TestCase("\u3002", "single separator U+3002"),
3740
TestCase("\uFF0E", "single separator U+FF0E"),
3841
TestCase("\uFF61", "single separator U+FF61"),

0 commit comments

Comments
 (0)