Skip to content

Commit 70feed7

Browse files
author
Antonis Lilis
committed
Fixes crash when comparing boolean with string
1 parent 088b3e8 commit 70feed7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class JsonLogic {
4141
evaluate(logic, data)
4242
} catch (e: kotlin.NotImplementedError) {
4343
false
44+
} catch (e: java.lang.Exception) {
45+
false
4446
}
4547
} else evaluate(logic, data)
4648

@@ -234,6 +236,7 @@ class JsonLogic {
234236
a is String && b is Number -> compareValues(a.doubleValue, b.toDouble())
235237
a is Number && b is String -> compareValues(a.toDouble(), b.doubleValue)
236238
a is String && b is String -> compareValues(a.toString().unStringify, b.toString().unStringify)
239+
a is Boolean || b is Boolean -> compareValues(a.truthy, b.truthy)
237240
else -> compareValues(a, b)
238241
}
239242

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,12 @@ class JsonLogicTests {
323323
val result = jsonLogic.apply(logic, data)
324324
assertEquals("null", result)
325325
}
326+
327+
@Test
328+
fun compareBooleanWithString() {
329+
val jsonLogic = JsonLogic()
330+
val logic = mapOf("==" to listOf("true", true))
331+
val result = jsonLogic.apply(logic)
332+
assertEquals("true", result)
333+
}
326334
}

0 commit comments

Comments
 (0)