Skip to content

Commit 449f53b

Browse files
committed
Resolve an issue with empty objects post-permissive
1 parent dffaef2 commit 449f53b

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

asyncLogic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class AsyncLogicEngine {
150150
return result
151151
}
152152

153-
if (logic && typeof logic === 'object') {
153+
if (logic && typeof logic === 'object' && Object.keys(logic).length > 0) {
154154
const { func, result } = await this._parse(logic, data, above)
155155

156156
if (this.options.yieldSupported && (await checkYield(result))) {

compiler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ function buildString (method, buildState = {}) {
272272
buildState.useContext || (engine.methods[func] || {}).useContext
273273

274274
if (method && typeof method === 'object') {
275+
if (!func) return pushValue(method)
275276
if (!engine.methods[func]) {
276277
// If we are in permissive mode, we will just return the object.
277278
if (engine.options.permissive) return pushValue(method, true)

general.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ describe('Various Test Cases', () => {
7777
for (const engine of normalEngines) await testEngine(engine, { unknown: true }, {}, Error)
7878
})
7979

80+
it('Should return an empty object when I pass in an empty object.', async () => {
81+
for (const engine of normalEngines) await testEngine(engine, {}, {}, {})
82+
for (const engine of permissiveEngines) await testEngine(engine, {}, {}, {})
83+
})
84+
8085
it('Should return the object when an unrecognized method is used.', async () => {
8186
for (const engine of permissiveEngines) {
8287
await testEngine(engine, { unknown: true }, {}, { unknown: true })

logic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class LogicEngine {
111111
}
112112
return result
113113
}
114-
if (logic && typeof logic === 'object') {
114+
if (logic && typeof logic === 'object' && Object.keys(logic).length > 0) {
115115
const { func, result } = this._parse(logic, data, above)
116116
if (this.options.yieldSupported && checkYield(result)) {
117117
if (result instanceof YieldStructure) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-engine",
3-
"version": "1.2.9",
3+
"version": "1.2.10",
44
"description": "Construct complex rules with JSON & process them.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

0 commit comments

Comments
 (0)