Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single equals in filter assigns value #210

Closed
v-mwalk opened this issue May 10, 2024 · 1 comment
Closed

Single equals in filter assigns value #210

v-mwalk opened this issue May 10, 2024 · 1 comment

Comments

@v-mwalk
Copy link

v-mwalk commented May 10, 2024

Describe the bug

A filter erroneously using a single equals in a comparison filter modifies the filtering property in the target object.

Code sample or steps to reproduce

const originalJSON = {
        testing: [
          { test: "hello1", prop1: "bye1",  prop2: "day1" },
          { test: "hello2", prop1: "bye2",  prop2: "day2" },
          { test: "hello3", prop1: "bye3",  prop2: "day3" },
        ],
      };

const filteredJSON = JSONPath({path: '$.testing[?(@.test="hello2"].prop1',json: originalJSON, resultType" 'all'}); // Note single equals in filter

//
// originalJSON now contains;
//        testing: [
//          { test: "hello2", prop1: "bye1",  prop2: "day1" },
//          { test: "hello2", prop1: "bye2",  prop2: "day2" },
//          { test: "hello2", prop1: "bye3",  prop2: "day3" },
//        ],
//      };
//
//

Expected behavior

As the filter is errored, would expect an exception to be thrown, for handling by the caller.

Environment (IMPORTANT)

  • JSONPath-Plus version: 8.0.1

Desktop**

  • OS: Mac
  • Node 19.8.1

Additional context

Can also be repo'd at jsonpath.com evaluator

@80avin
Copy link
Contributor

80avin commented Sep 30, 2024

This is fixed by #185 already

Run the browser demo with

eval = 'safe'

filter=

$.testing[?(@.test="hello2")].test

JSON Sample:

{
  "testing": [
    {
      "test": "hello1",
      "prop1": "bye1",
      "prop2": "day1"
    },
    {
      "test": "hello2",
      "prop1": "bye2",
      "prop2": "day2"
    },
    {
      "test": "hello3",
      "prop1": "bye3",
      "prop2": "day3"
    }
  ]
}

@brettz9 brettz9 closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants