Skip to content

Commit f3339d8

Browse files
committed
Correct conditions in equality check to prepare for YAML
1 parent e57aaf2 commit f3339d8

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/util/ElementEqualityUtil.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,12 @@ internal fun areEqualPrimitives(
4040
if (first.isString != second.isString) {
4141
return false
4242
}
43-
return if (first.isString) {
44-
first.content == second.content
45-
} else {
46-
when {
47-
first.isNull || second.isNull -> false
48-
// probably content should be compared ignoring the case - YAML allows different values for boolean
49-
first.isBoolean || second.isBoolean -> first.content == second.content
50-
else -> compareAsNumbers(first, second)
51-
}
43+
return when {
44+
first.isNumber && second.isNumber -> compareAsNumbers(first, second)
45+
// probably content should be compared ignoring the case - YAML allows different values for boolean
46+
first.isBoolean && second.isBoolean -> first.content == second.content
47+
first.isString -> first.content == second.content
48+
else -> false
5249
}
5350
}
5451

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/util/NumberParts.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ internal data class NumberParts(
99
val precision: Int,
1010
)
1111

12-
internal fun parseNumberParts(element: PrimitiveElement): NumberParts? {
13-
return if (element.isString || element.isNull || element.isBoolean) {
14-
null
15-
} else {
12+
internal fun parseNumberParts(element: PrimitiveElement): NumberParts? =
13+
if (element.isNumber) {
1614
numberParts(element)
15+
} else {
16+
null
1717
}
18-
}
1918

2019
private const val E_SMALL_CHAR: Char = 'e'
2120
private const val E_BIG_CHAR: Char = 'E'

0 commit comments

Comments
 (0)