From 6071bad3c952a007357b5c20500a06827f4c949d Mon Sep 17 00:00:00 2001 From: Sam Lee-Lindsay Date: Wed, 24 Jul 2024 17:15:49 +1000 Subject: [PATCH] Fix(SCIMMY.Types.Filter): be more specific with coercion of true/false to boolean Only cast from string to boolean when comparing for equality, and when actual value is also a boolean. --- src/lib/types/filter.js | 5 +++-- test/lib/types/filter.json | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/types/filter.js b/src/lib/types/filter.js index a3e63c3..0ac2911 100644 --- a/src/lib/types/filter.js +++ b/src/lib/types/filter.js @@ -311,8 +311,9 @@ export class Filter extends Array { const negate = (expression[0].toLowerCase() === "not"); let [comparator, expected] = expression.slice(((+negate) - expression.length)); - // Cast true and false strings to boolean values - expected = (expected === "false" ? false : (expected === "true" ? true : expected)); + // For equality tests, cast true and false strings to boolean values, maintaining EntraID support + if (["eq", "ne"].includes(comparator.toLowerCase()) && typeof actual === "boolean" && typeof expected === "string") + expected = (expected.toLowerCase() === "false" ? false : (expected.toLowerCase() === "true" ? true : expected)); switch (comparator.toLowerCase()) { default: diff --git a/test/lib/types/filter.json b/test/lib/types/filter.json index 1e3fd49..09c3353 100644 --- a/test/lib/types/filter.json +++ b/test/lib/types/filter.json @@ -293,7 +293,10 @@ {"expression": {"userName": ["np"]}, "expected": []}, {"expression": {"exists": ["np"]}, "expected": [2, 4]}, {"expression": {"exists": ["eq", null]}, "expected": [2, 4]}, - {"expression": {"exists": ["ne", null]}, "expected": [1, 3]} + {"expression": {"exists": ["ne", null]}, "expected": [1, 3]}, + {"expression": {"exists": ["eq", true]}, "expected": [1]}, + {"expression": {"exists": ["eq", "True"]}, "expected": [1]}, + {"expression": {"exists": ["eq", "False"]}, "expected": [3]} ], "nesting": [ {"expression": {"name": {"formatted": ["co", "a"]}}, "expected": [1, 2, 4]},