Skip to content

Commit 705cdb8

Browse files
committed
Revert "Correct conditions in equality check to prepare for YAML"
Don't see any possibility to use Kaml in the nearest future. Better to use operation with less cost first This reverts commit f3339d8.
1 parent 37f84a3 commit 705cdb8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

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

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

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

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

1920
private const val E_SMALL_CHAR: Char = 'e'
2021
private const val E_BIG_CHAR: Char = 'E'

0 commit comments

Comments
 (0)