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

String expressions fail when properties are in an object #12

Open
dpdonohue opened this issue Nov 14, 2015 · 4 comments
Open

String expressions fail when properties are in an object #12

dpdonohue opened this issue Nov 14, 2015 · 4 comments

Comments

@dpdonohue
Copy link

Joe I like this tool!
I ran this unit test, which is similar to your existing unit test. It always returns false/0

'filtrex: object string test': function(test) {
        test.equal(1, compileExpression('obj.foo == "hello"')({obj:{foo:'hello'}}));
        test.equal(0, compileExpression('obj.foo == "hello"')({obj:{foo:'bye'}}));
        test.equal(0, compileExpression('obj.foo != "hello"')({obj:{foo:'hello'}}));
        test.equal(1, compileExpression('obj.foo != "hello"')({obj:{foo:'bye'}}));
        test.equal(true, compileExpression('obj.foo in ("aa", "bb")')({obj:{foo:'aa'}}));
        test.equal(false, compileExpression('obj.foo in ("aa", "bb")')({obj:{foo:'c'}}));
        test.equal(false, compileExpression('obj.foo not in ("aa", "bb")')({obj:{foo:'aa'}}));
        test.equal(true, compileExpression('obj.foo not in ("aa", "bb")')({obj:{foo:'cc'}}));
    }
@dpdonohue dpdonohue changed the title String expressions fail when properties are in an object, using dot notation String expressions fail when properties are in an object Nov 14, 2015
@dpdonohue
Copy link
Author

So Filtrex fails to match strings when they are nested inside an object. Do you think this is a problem with Filtrex or with the underlying jison engine?

@joewalnes
Copy link
Owner

Filtrex does not support nested expressions. I haven't added it because there's a lot of edge cases I'd like to think through first.

To handle this, you'll have to write code that flattens your structure into a single nested object.

For example, convert this:

{
  obj: {
    foo:'a',
    bar:'b'
  }
}

into this:

{
  'obj.foo': 'a',
  'obj.bar': 'b'
}

cdauth added a commit to FacilMap/facilmap that referenced this issue Nov 14, 2017
Related to issue joewalnes/filtrex#12, filtrex
does not support nested properties.
@serhiisol
Copy link

For a temp solution you can use https://www.npmjs.com/package/flat package :)

@cshaa
Copy link
Contributor

cshaa commented Mar 1, 2020

Also, the new filtrex supports the of operator:

let f = compileExpression('version of software >= 1.4')
f({ software: {name: 'Foo', version: 2} }) // true
f({ software: {name: 'bar', version: 1} }) // false

Using version of software instead of software.version might feel backwards for a developer, but it is closer to plain English, so we went with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants