Skip to content

Commit 1c8914d

Browse files
author
Antonis Lilis
committed
Fixes faulty string comparison bug
1 parent 40b1e58 commit 1c8914d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/kotlin/eu/afse/jsonlogic/JsonLogic.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class JsonLogic {
230230

231231
private fun compareStrict(a: Comparable<*>?, b: Comparable<*>?) = when {
232232
a is Number && b is Number -> compareValues(a.toDouble(), b.toDouble())
233-
a is String && b is String -> compareValues(a.doubleValue, b.doubleValue)
233+
a is String && b is String -> compareValues(a.unStringify, b.unStringify)
234234
else -> -1
235235
}
236236

src/test/kotlin/eu/afse/jsonlogic/JsonLogicTests.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@ class JsonLogicTests {
154154
val result = jsonLogic.apply(mapOf("pow" to listOf(3,2)))
155155
assertEquals("9.0", result)
156156
}
157+
158+
@Test
159+
fun stringComparisonBug() {
160+
val jsonLogic = JsonLogic()
161+
val logic = mapOf("===" to listOf(mapOf("var" to listOf("a")), "two"))
162+
val data = mapOf("a" to "one")
163+
val result = jsonLogic.apply(logic, data)
164+
assertEquals("false", result)
165+
}
157166
}

0 commit comments

Comments
 (0)