Skip to content

Commit

Permalink
Fix(SCIMMY.Types.Filter): be more specific with coercion of true/fals…
Browse files Browse the repository at this point in the history
…e to boolean

Only cast from string to boolean when comparing for equality, and when actual value is also a boolean.
  • Loading branch information
sleelin committed Jul 24, 2024
1 parent 278b017 commit 6071bad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/lib/types/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion test/lib/types/filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]},
Expand Down

0 comments on commit 6071bad

Please sign in to comment.