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

"non-existent variable" and "!=" expression should return false #57

Closed
smartsl opened this issue Nov 26, 2021 · 1 comment
Closed

"non-existent variable" and "!=" expression should return false #57

smartsl opened this issue Nov 26, 2021 · 1 comment
Labels
question Further information is requested

Comments

@smartsl
Copy link

smartsl commented Nov 26, 2021

For example:

<script src="filtrex.2.2.0.min.js"></script>
<pre>
<script>
var fn1 = filtrex.compileExpression("x==1");
document.write('{x:1}:',fn1({x:1}),"\n"); //1
document.write('{x:2}:',fn1({x:2}),"\n"); //0
document.write('{y:1}:',fn1({y:1}),"\n"); //0

var fn2 = filtrex.compileExpression("x!=1");
document.write('{x:1}:',fn2({x:1}),"\n"); //0
document.write('{x:2}:',fn2({x:2}),"\n"); //1
document.write('{y:1}:',fn2({y:1}),"\n"); //1 (this should be 0)

var fn3 = filtrex.compileExpression("x!=1 and x!=null");
document.write('{x:1}:',fn3({x:1}),"\n"); //0
document.write('{x:2}:',fn3({x:2}),"\n"); //1
document.write('{y:1}:',fn3({y:1}),"\n"); //0 (this is ok)
</script>
</pre>

I can resolve this by using x!=1 and x!=null, but a little troublesome.

Could you provide a way to make that default false? Maybe add an option or something.

@cshaa
Copy link
Owner

cshaa commented Dec 6, 2021

Hey @smartsl!
Starting with Filtrex v3, trying to access an undefined property will result in an error (#22). However, also in Filtrex v3 you can overload any operator to do whatever you want (#30), so there should be a way for you to make Filtrex do whatever you need.

However, you should know that I don't think that x != 1 evaluating to false for anything else than { x: 1 } is good UX.

@cshaa cshaa added the question Further information is requested label Dec 6, 2021
@cshaa cshaa closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants