Skip to content

[bug] Conditional then/else only works with primitives  #6

@scott-wyatt

Description

@scott-wyatt

@TotalTechGeek awesome job with the traversal stuff! We made the switch to this library for that functionality.

if/and/or works as expected if it returns a string, number, or boolean. However, if the if conditional returns an object, it returns undefined because https://github.com/TotalTechGeek/json-logic-engine/blob/master/defaultMethods.js#L53 returns this as a context for another rule. It seems to me that the expected behavior would be that if the context is not a rule, it should just return the object.

TLDR; If I use JSON logic conditional that returns an object that is not a rule then I get the object back, if I use JSON Logic Engine I do not.

This might all be fixed if _parse would just return data if not satisfied.

Quick way to reproduce the issue is:

 
    const data = {
      first_name: true
    }

    const rule = {
      if: [
        {
          "===": [
            {
              var: "first_name"
            },
            true
          ]
        },
        { first_name: "scott" },
        { first_name: "no idea" }
      ]
    }

    const result = logic.run(rule, data)

    console.log(result) // 'undefined'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions