TomFrost / Jexl

Javascript Expression Language: Powerful context-based expression parser and evaluator
MIT License
561 stars 92 forks source link

null values cause error #64

Closed alberts-diterihs closed 4 years ago

alberts-diterihs commented 4 years ago

Since version 2.2.0. Null values in context are treated differently.

Example:

const jexl = require("jexl");
const context = {
  data: {
    author: null
  }
};

const test = jexl.evalSync('data.author != null && data.author.id == "1"', context);
console.log(test);

In v2.1.1 variable test is set to false as it should be. In v2.2.1 an error is thrown Error: Error: TypeError: Cannot read property 'id' of null. And null check like so: data.author != null && does not help.

Weirdly enough if author in context is set to undefined, it works as expected by returning false.

Shouldn't null values be handled in similar way to undefined values?

TomFrost commented 4 years ago

This is a great catch, and you’re absolutely right. I’m going to look into this. The way you phrased the issue sounds like this was working appropriately on an earlier version of Jexl — is that the case? And if so, do you recall the version it worked on? Assuming anything previous to 2.2.0 but I want to be sure.

Thanks!

alberts-diterihs commented 4 years ago

Yes it was working before. v2.1.1 was working fine, but v2.2.0 and further has this issue.

TomFrost commented 4 years ago

Fix published in v2.2.2!