filtrex icon indicating copy to clipboard operation
filtrex copied to clipboard

Expressions with Spaces

Open jfinch1991 opened this issue 9 years ago • 8 comments

Im trying to get this to parse expressions with spaces e.g. Net Income > 10000. I have tried a few things like wrapping with quotes "Net Income" but that hasn't worked. Any ideas?

jfinch1991 avatar Feb 27 '17 20:02 jfinch1991

Use single quotes:

var e = "'a b' > 3"                                                             
var f = compileExpression(e)                                                    
f({"a b": 1}) // 0                                                              
f({"a b": 4}) // 1

msantos avatar Feb 27 '17 20:02 msantos

met the same issue, tried using quotes, but it doesn't work, showing: Unrecognized text error

Any advice?

summer9090 avatar Jun 09 '17 02:06 summer9090

If you want help, show the code that isn't working.

To debug this yourself, open a page that loads filtrex. Then open the javascript console and enter in the code from https://github.com/joewalnes/filtrex/issues/14#issuecomment-282844804. Change the expression to match your input and re-test.

msantos avatar Jun 09 '17 14:06 msantos

I am using the same example you replied @jfinch1991 , the code is as follows:

function hello() { var e = "'a b' > 3" var myfilter = compileExpression(e); myfilter({"a b": 2}); }

Uncaught Error: Lexical error on line 1. Unrecognized text. 'a b' > 3 ^

Thanks for advice

summer9090 avatar Jun 12 '17 02:06 summer9090

Works for me. Try running the tests, in particular check the test for "quoted symbols" passes. To be sure, you can add a test case with whitespace:

diff --git a/test/filtrex-test.html b/test/filtrex-test.html
index d0ba6ed..49a5afe 100644
--- a/test/filtrex-test.html
+++ b/test/filtrex-test.html
@@ -128,6 +128,7 @@ tests({

     'quoted symbols': function() {
         eq(123, compileExpression('\'hello-world-foo\'')({'hello-world-foo': 123}));
+        eq(123, compileExpression('\'hello world foo\'')({'hello world foo': 123}));
         eq(123, compileExpression('\'order+goo*and#stuff\'')({'order+goo*and#stuff': 123}));
     },

If the tests work, verify your version of filtrex.js is up to date.

msantos avatar Jun 14 '17 23:06 msantos

Thanks for your reply.

I cloned this project and run the tests, all passed. But in my project, I installed filtrex(version: 0.5.4) through npm. When I run the same test('quoted symbol'), it will pop up the errors above. Is the filtrex version in node repository the latest one?

Thanks.

summer9090 avatar Jun 19 '17 05:06 summer9090

Any updates about the issue?

Thanks

summer9090 avatar Aug 02 '17 07:08 summer9090

The issue was caused by NPM not being up-to-date. As of 2019 this is no longer the case and the NPM package is being actively maintained again.

cshaa avatar Mar 01 '20 14:03 cshaa