Skip to content

Commit e4defe3

Browse files
committed
Merge branch 'fix/avoid-null-cases-for-isempty-operator' into 'master'
feat: Validated null cases for isEmpty operator See merge request auto-cloud/cloudgraph/sdk!58
2 parents b40db40 + d142342 commit e4defe3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/rules-engine/operators/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
}
99

1010
// Verify empty/filled objects
11-
if (typeof data === 'object') {
11+
if (typeof data === 'object' && data !== null) {
1212
const hasKeys = Object.keys(data).length
1313
return shouldBeEmpty ? hasKeys === 0 : hasKeys > 0
1414
}

tests/operators/common.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@ describe('Common Operators', () => {
2626
test('Should fail given a filled object', () => {
2727
expect(CommonOperators.isEmpty({ key: 'one' }, true)).toBeFalsy()
2828
})
29+
test('Should fail given a null value', () => {
30+
expect(CommonOperators.isEmpty(null, true)).toBeFalsy()
31+
})
32+
test('Should fail given an undefined value', () => {
33+
expect(CommonOperators.isEmpty(undefined, true)).toBeFalsy()
34+
})
35+
test('Should fail given an integer', () => {
36+
expect(CommonOperators.isEmpty(33, true)).toBeFalsy()
37+
})
38+
test('Should fail given a string', () => {
39+
expect(CommonOperators.isEmpty('string', true)).toBeFalsy()
40+
})
41+
test('Should fail given a boolean', () => {
42+
expect(CommonOperators.isEmpty(true, true)).toBeFalsy()
43+
})
2944
})
3045
})

0 commit comments

Comments
 (0)