diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f876dada..b5765f938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Fixed +[#569](https://github.com/plotly/dash-table/issues/569), [#544](https://github.com/plotly/dash-table/issues/544) +- Allow empty strings in all `filter_query` (e.g filter_query: '{colA} eq ""') + [#567](https://github.com/plotly/dash-table/issues/567) - Add support for missing `border-radius` in style_** props - Fix table's inner vs. outer container styling diff --git a/src/dash-table/syntax-tree/lexeme/expression.ts b/src/dash-table/syntax-tree/lexeme/expression.ts index 730586a6a..fd7032ae4 100644 --- a/src/dash-table/syntax-tree/lexeme/expression.ts +++ b/src/dash-table/syntax-tree/lexeme/expression.ts @@ -4,7 +4,7 @@ import { LexemeType, IUnboundedLexeme } from 'core/syntax-tree/lexicon'; import { ISyntaxTree } from 'core/syntax-tree/syntaxer'; const FIELD_REGEX = /^{(([^{}\\]|\\.)+)}/; -const STRING_REGEX = /^(('([^'\\]|\\.)+')|("([^"\\]|\\.)+")|(`([^`\\]|\\.)+`))/; +const STRING_REGEX = /^(('([^'\\]|\\.)*')|("([^"\\]|\\.)*")|(`([^`\\]|\\.)*`))/; const VALUE_REGEX = /^(([^\s'"`{}()\\]|\\.)+)(?:[\s)]|$)/; const getField = ( diff --git a/tests/cypress/tests/unit/lexeme_test.ts b/tests/cypress/tests/unit/lexeme_test.ts index d924c4e9a..610acfef0 100644 --- a/tests/cypress/tests/unit/lexeme_test.ts +++ b/tests/cypress/tests/unit/lexeme_test.ts @@ -39,6 +39,7 @@ describe('expression', () => { expect(typeof stringExpression.resolve).to.equal('function'); if (stringExpression.resolve) { + expect(stringExpression.resolve(undefined, { value: '\'\'' } as ISyntaxTree)).to.equal(''); expect(stringExpression.resolve(undefined, { value: '\'abc\'' } as ISyntaxTree)).to.equal('abc'); expect(stringExpression.resolve(undefined, { value: '"abc"' } as ISyntaxTree)).to.equal('abc'); expect(stringExpression.resolve(undefined, { value: '`abc`' } as ISyntaxTree)).to.equal('abc'); diff --git a/tests/cypress/tests/unit/query_syntactic_tree_test.ts b/tests/cypress/tests/unit/query_syntactic_tree_test.ts index 5c2adba98..9af69d3e4 100644 --- a/tests/cypress/tests/unit/query_syntactic_tree_test.ts +++ b/tests/cypress/tests/unit/query_syntactic_tree_test.ts @@ -264,6 +264,15 @@ describe('Query Syntax Tree', () => { expect(tree.evaluate(data2)).to.equal(false); expect(tree.evaluate(data3)).to.equal(false); }); + + it('can compare to empty string', () => { + const tree = new QuerySyntaxTree('{c} eq ""'); + + expect(tree.isValid).to.equal(true); + expect(tree.evaluate({ c: 'a' })).to.equal(false); + expect(tree.evaluate({ c: ' ' })).to.equal(false); + expect(tree.evaluate({ c: '' })).to.equal(true); + }); }); describe('block', () => {