jetstreamapp / soql-parser-js

Javascript SOQL parser
https://jetstreamapp.github.io/soql-parser-js/
MIT License
77 stars 20 forks source link

Invalid JSON when query contains two consecutive NOT Operators #237

Closed MirzaHamza00 closed 8 months ago

MirzaHamza00 commented 8 months ago

Description

Since SOQL lacks the NOT LIKE operator, the alternative is NOT City LIKE '%123%', and the parser correctly parses it into JSON. image

However, when I attempted to negate the entire query by enclosing it with the NOT operator, the parser treated it as a single entity and returned a JSON with corruption. image

The placement of "NOT" is causing confusion, as it's unclear whether it belongs to a specific LIKE operator or if it negates the entire query.

paustint commented 8 months ago

@MirzaHamza00 - Thank you for reporting this, and there is definitely a bug with this. I think the latest query you shared is not actually valid

WHERE NOT (NOT BillingCity LIKE '%123%' AND id = null) does not run in the dev console, so I think it is invalid to have an AND statement within the parentheses.

I tested with SELECT Id, BillingCity FROM Account WHERE NOT (NOT BillingCity LIKE '%123%') and this produced invalid JSON that could not be composed into a valid query.

If you have any other test-cases that I can test this with, let me know and I can make sure that they work correctly.

I am working on a fix now - and the output will look like this SELECT Id, BillingCity FROM Account WHERE NOT (NOT BillingCity LIKE '%123%')

{
  fields: [
    { type: 'Field', field: 'Id' },
    { type: 'Field', field: 'BillingCity' },
  ],
  sObject: 'Account',
  where: {
    left: null,
    operator: 'NOT',
    right: {
      left: {
        openParen: 1,
      },
      operator: 'NOT',
      right: {
        left: {
          field: 'BillingCity',
          operator: 'LIKE',
          value: `'%123%'`,
          literalType: 'STRING',
          closeParen: 1,
        },
      },
    },
  },
}
paustint commented 8 months ago

Not the same, but very similar issue https://github.com/jetstreamapp/jetstream/issues/702