Skip to content

Commit

Permalink
Resolve an issue with empty objects post-permissive
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalTechGeek committed Sep 14, 2023
1 parent dffaef2 commit 449f53b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion asyncLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AsyncLogicEngine {
return result
}

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

if (this.options.yieldSupported && (await checkYield(result))) {
Expand Down
1 change: 1 addition & 0 deletions compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function buildString (method, buildState = {}) {
buildState.useContext || (engine.methods[func] || {}).useContext

if (method && typeof method === 'object') {
if (!func) return pushValue(method)
if (!engine.methods[func]) {
// If we are in permissive mode, we will just return the object.
if (engine.options.permissive) return pushValue(method, true)
Expand Down
5 changes: 5 additions & 0 deletions general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ describe('Various Test Cases', () => {
for (const engine of normalEngines) await testEngine(engine, { unknown: true }, {}, Error)
})

it('Should return an empty object when I pass in an empty object.', async () => {
for (const engine of normalEngines) await testEngine(engine, {}, {}, {})
for (const engine of permissiveEngines) await testEngine(engine, {}, {}, {})
})

it('Should return the object when an unrecognized method is used.', async () => {
for (const engine of permissiveEngines) {
await testEngine(engine, { unknown: true }, {}, { unknown: true })
Expand Down
2 changes: 1 addition & 1 deletion logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LogicEngine {
}
return result
}
if (logic && typeof logic === 'object') {
if (logic && typeof logic === 'object' && Object.keys(logic).length > 0) {
const { func, result } = this._parse(logic, data, above)
if (this.options.yieldSupported && checkYield(result)) {
if (result instanceof YieldStructure) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-logic-engine",
"version": "1.2.9",
"version": "1.2.10",
"description": "Construct complex rules with JSON & process them.",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down

0 comments on commit 449f53b

Please sign in to comment.