From 5a333c4e77fe02804c2a44920d28c6e0911753dd Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Wed, 2 Oct 2019 17:30:59 -0400 Subject: [PATCH 01/16] Add spaces to regex for relational operators. --- src/dash-table/syntax-tree/lexeme/relational.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 06eec9129..4a1520f78 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -67,19 +67,19 @@ export const equal: IUnboundedLexeme = R.merge({ op === exp ), subType: RelationalOperator.Equal, - regexp: /^(=|eq)/i + regexp: /^(=|eq\s)/i }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, - regexp: /^(>=|ge)/i + regexp: /^(>=|ge\s)/i }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, - regexp: /^(>|gt)/i + regexp: /^(>|gt\s)/i }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = { @@ -106,13 +106,13 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ export const lessOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op <= exp), subType: RelationalOperator.LessOrEqual, - regexp: /^(<=|le)/i + regexp: /^(<=|le\s)/i }, LEXEME_BASE); export const lessThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op < exp), subType: RelationalOperator.LessThan, - regexp: /^(<|lt)/i + regexp: /^(<|lt\s)/i }, LEXEME_BASE); export const notEqual: IUnboundedLexeme = R.merge({ From 5f2d050334ff5f010eb534e21730e73334f671cc Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 4 Oct 2019 11:24:09 -0400 Subject: [PATCH 02/16] Add and adjust tests for relational operators. Since gt is now interpreted as a string, it was removed from the invalid filters test. --- .../tests/standalone/filtering_test.ts | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/cypress/tests/standalone/filtering_test.ts b/tests/cypress/tests/standalone/filtering_test.ts index 6a23a6e62..cccc59920 100644 --- a/tests/cypress/tests/standalone/filtering_test.ts +++ b/tests/cypress/tests/standalone/filtering_test.ts @@ -71,8 +71,6 @@ describe('filter', () => { .within(() => cy.get('.dash-cell-value') .then($el => cell_1 = $el[0].innerHTML)); - DashTable.getFilterById('ccc').click(); - DOM.focused.type(`gt`); DashTable.getFilterById('ddd').click(); DOM.focused.type('"20 a000'); DashTable.getFilterById('eee').click(); @@ -85,12 +83,10 @@ describe('filter', () => { DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', cell_1)); DashTable.getFilterById('bbb').within(() => cy.get('input').should('have.value', '! !"')); - DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'gt')); DashTable.getFilterById('ddd').within(() => cy.get('input').should('have.value', '"20 a000')); DashTable.getFilterById('eee').within(() => cy.get('input').should('have.value', 'is prime2')); DashTable.getFilterById('bbb').should('have.class', 'invalid'); - DashTable.getFilterById('ccc').should('have.class', 'invalid'); DashTable.getFilterById('ddd').should('have.class', 'invalid'); DashTable.getFilterById('eee').should('have.class', 'invalid'); }); @@ -113,14 +109,33 @@ describe('filter', () => { DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '100')); }); + it.only('does not use relational operators unless they are followed by a space', () => { + DashTable.getCellById(2, 'ccc').click(); + DOM.focused.type(`le5${Key.Enter}`); + + DashTable.getFilterById('ccc').click(); + DOM.focused.type(`le5${Key.Enter}`); + DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', 'le5')); + DashTable.getCellById(0, 'rows').within(() => cy.get('.dash-cell-value').should('have.html', '3')); + + cy.get('.clear-filters').click(); + + DashTable.getFilterById('ccc').click(); + DOM.focused.type(`le 5${Key.Enter}`); + DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '1')); + DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '2')); + DashTable.getCellById(2, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '4')); + DashTable.getCellById(3, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '5')); + }); + it('typing invalid followed by valid query fragment does not reset invalid', () => { DashTable.getFilterById('ccc').click(); - DOM.focused.type(`gt`); + DOM.focused.type(`is prime2`); DashTable.getFilterById('ddd').click(); DOM.focused.type('lt 20000'); DashTable.getFilterById('eee').click(); - DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'gt')); + DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'is prime2')); DashTable.getFilterById('ddd').within(() => cy.get('input').should('have.value', 'lt 20000')); }); From ddb903db654d006525fb701c7ca34da025bd5f58 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 4 Oct 2019 14:27:09 -0400 Subject: [PATCH 03/16] Add spaces to remaining relational operators. --- src/dash-table/syntax-tree/lexeme/relational.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 4a1520f78..5ba8f3bb8 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -57,7 +57,7 @@ export const contains: IUnboundedLexeme = R.merge({ op.toString().indexOf(exp.toString()) !== -1 ), subType: RelationalOperator.Contains, - regexp: /^(contains)/i + regexp: /^(contains\s)/i }, LEXEME_BASE); export const equal: IUnboundedLexeme = R.merge({ @@ -100,7 +100,7 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ normalizedOp.indexOf(normalizedExp) === 0; }), subType: RelationalOperator.DateStartsWith, - regexp: /^(datestartswith)/i + regexp: /^(datestartswith\s)/i }, LEXEME_BASE); export const lessOrEqual: IUnboundedLexeme = R.merge({ From 96ba2b2c143dc54eeeaffc66ebe649e1c275cc27 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 4 Oct 2019 14:38:03 -0400 Subject: [PATCH 04/16] Add test for symbol-based operators that aren't followed by a space. --- tests/cypress/tests/standalone/filtering_test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/cypress/tests/standalone/filtering_test.ts b/tests/cypress/tests/standalone/filtering_test.ts index cccc59920..23e41fe1c 100644 --- a/tests/cypress/tests/standalone/filtering_test.ts +++ b/tests/cypress/tests/standalone/filtering_test.ts @@ -109,7 +109,7 @@ describe('filter', () => { DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '100')); }); - it.only('does not use relational operators unless they are followed by a space', () => { + it('does not use text-based relational operators unless they are followed by a space', () => { DashTable.getCellById(2, 'ccc').click(); DOM.focused.type(`le5${Key.Enter}`); @@ -128,6 +128,16 @@ describe('filter', () => { DashTable.getCellById(3, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '5')); }); + it('uses symbol relational operators that are not followed by a space', () => { + DashTable.getFilterById('ccc').click(); + DOM.focused.type(`<=5${Key.Enter}`); + DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '1')); + DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '2')); + DashTable.getCellById(2, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '3')); + DashTable.getCellById(3, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '4')); + DashTable.getCellById(4, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '5')); + }); + it('typing invalid followed by valid query fragment does not reset invalid', () => { DashTable.getFilterById('ccc').click(); DOM.focused.type(`is prime2`); From 8da1189900ee04377cc70cb1b8d8f7e51c32a472 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 4 Oct 2019 16:42:59 -0400 Subject: [PATCH 05/16] Update src/dash-table/syntax-tree/lexeme/relational.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Marc-André Rivet --- src/dash-table/syntax-tree/lexeme/relational.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 5ba8f3bb8..542dcd016 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -57,7 +57,7 @@ export const contains: IUnboundedLexeme = R.merge({ op.toString().indexOf(exp.toString()) !== -1 ), subType: RelationalOperator.Contains, - regexp: /^(contains\s)/i + regexp: /^(contains(\s|$))/i }, LEXEME_BASE); export const equal: IUnboundedLexeme = R.merge({ @@ -119,4 +119,4 @@ export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, regexp: /^(!=|ne)/i -}, LEXEME_BASE); \ No newline at end of file +}, LEXEME_BASE); From f3123263fa277ed40a6d250f44445f0455f06035 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 4 Oct 2019 17:07:30 -0400 Subject: [PATCH 06/16] Add space to regex for notEqual. --- src/dash-table/syntax-tree/lexeme/relational.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 542dcd016..74c087f88 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -118,5 +118,5 @@ export const lessThan: IUnboundedLexeme = R.merge({ export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, - regexp: /^(!=|ne)/i + regexp: /^(!=|ne\s)/i }, LEXEME_BASE); From d5a39c19477c1441d5add6702844b872d04ce9f8 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 10:33:58 -0400 Subject: [PATCH 07/16] Add support for incomplete queries. --- src/dash-table/syntax-tree/lexeme/relational.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 74c087f88..28c8ea869 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -67,19 +67,19 @@ export const equal: IUnboundedLexeme = R.merge({ op === exp ), subType: RelationalOperator.Equal, - regexp: /^(=|eq\s)/i + regexp: /^(=|eq(\s|$))/i }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, - regexp: /^(>=|ge\s)/i + regexp: /^(>=|ge(\s|$))/i }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, - regexp: /^(>|gt\s)/i + regexp: /^(>|gt(\s|$))/i }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = { @@ -100,23 +100,23 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ normalizedOp.indexOf(normalizedExp) === 0; }), subType: RelationalOperator.DateStartsWith, - regexp: /^(datestartswith\s)/i + regexp: /^(datestartswith(\s|$))/i }, LEXEME_BASE); export const lessOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op <= exp), subType: RelationalOperator.LessOrEqual, - regexp: /^(<=|le\s)/i + regexp: /^(<=|le(\s|$))/i }, LEXEME_BASE); export const lessThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op < exp), subType: RelationalOperator.LessThan, - regexp: /^(<|lt\s)/i + regexp: /^(<|lt(\s|$))/i }, LEXEME_BASE); export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, - regexp: /^(!=|ne\s)/i + regexp: /^(!=|ne(\s|$))/i }, LEXEME_BASE); From c2a906b6881411e9b84d57c8d3bcfce3b47cbcc1 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 10:36:51 -0400 Subject: [PATCH 08/16] Add CHANGELOG entry. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35467a070..82ad6d64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Include input box for user to navigate directly to a page ### Fixed + [#460](https://github.com/plotly/dash-table/issues/460) - The `datestartswith` relational operator now supports number comparison - Fixed a bug where the implicit operator for columns was `equal` instead of the expected default for the column type @@ -34,6 +35,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). [#546](https://github.com/plotly/dash-table/issues/546) - Visible columns are used correctly for both header and data rows +[#563](https://github.com/plotly/dash-table/issues/563) +- Fixed a bug where any string beginning with a relational operator was being interpreted as that operator being applied to the rest of the string (e.g., "lens" was interpreted as "<=ns") + [#591](https://github.com/plotly/dash-table/issues/591) - Fixed row and column selection when multiple tables are present From fe9fae74cefd020fe1cc79c3f5eee0ef515f1a26 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 11:33:30 -0400 Subject: [PATCH 09/16] Add unit tests. --- .../cypress/tests/unit/query_syntactic_tree_test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/cypress/tests/unit/query_syntactic_tree_test.ts b/tests/cypress/tests/unit/query_syntactic_tree_test.ts index f99010eea..46a908381 100644 --- a/tests/cypress/tests/unit/query_syntactic_tree_test.ts +++ b/tests/cypress/tests/unit/query_syntactic_tree_test.ts @@ -589,5 +589,17 @@ describe('Query Syntax Tree', () => { expect(tree.evaluate({ a: 'abc v' })).to.equal(true); expect(tree.evaluate({ a: 'abc w' })).to.equal(false); }); + + it('correctly interprets text-based with no spaces as invalid', () => { + const tree = new QuerySyntaxTree('{a} le5'); + expect(tree.isValid).to.equal(false); + }); + + it.only('correctly interprets non-text-based with no spaces as valid', () => { + const tree = new QuerySyntaxTree('{a}<=5'); + expect(tree.isValid).to.equal(true); + expect(tree.evaluate({ a: 4 })).to.equal(true); + + }); }); }); \ No newline at end of file From 1018bb517b0ab43b843d4092337a519a9745e64b Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 11:52:34 -0400 Subject: [PATCH 10/16] Update tests/cypress/tests/unit/query_syntactic_tree_test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Marc-André Rivet --- tests/cypress/tests/unit/query_syntactic_tree_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/tests/unit/query_syntactic_tree_test.ts b/tests/cypress/tests/unit/query_syntactic_tree_test.ts index 46a908381..6cddb8572 100644 --- a/tests/cypress/tests/unit/query_syntactic_tree_test.ts +++ b/tests/cypress/tests/unit/query_syntactic_tree_test.ts @@ -595,11 +595,11 @@ describe('Query Syntax Tree', () => { expect(tree.isValid).to.equal(false); }); - it.only('correctly interprets non-text-based with no spaces as valid', () => { + it('correctly interprets non-text-based with no spaces as valid', () => { const tree = new QuerySyntaxTree('{a}<=5'); expect(tree.isValid).to.equal(true); expect(tree.evaluate({ a: 4 })).to.equal(true); }); }); -}); \ No newline at end of file +}); From aae4907ec4e757a4751080fdb676bf342a9bfda7 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 14:12:16 -0400 Subject: [PATCH 11/16] Trim filter values. --- src/dash-table/syntax-tree/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-table/syntax-tree/index.ts b/src/dash-table/syntax-tree/index.ts index e4d03607c..89dc5ae04 100644 --- a/src/dash-table/syntax-tree/index.ts +++ b/src/dash-table/syntax-tree/index.ts @@ -49,9 +49,9 @@ export const getSingleColumnMap = ( } if (s.lexeme.present && s.lexeme.present(s) === RelationalOperator.Equal) { - map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.right.value}`, column)); + map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.right.value.trim()}`, column)); } else { - map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.value} ${s.right.value}`, column)); + map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.value.trim()} ${s.right.value.trim()}`, column)); } } }, statements); From 6140a88d950fb06905b884d2c1ffdd208a45aca8 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 15:36:42 -0400 Subject: [PATCH 12/16] Ensure that trailing space does not get captured. --- src/dash-table/syntax-tree/lexeme/relational.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 28c8ea869..1f46abb86 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -57,7 +57,7 @@ export const contains: IUnboundedLexeme = R.merge({ op.toString().indexOf(exp.toString()) !== -1 ), subType: RelationalOperator.Contains, - regexp: /^(contains(\s|$))/i + regexp: /^((contains)(?:\s|$))/i }, LEXEME_BASE); export const equal: IUnboundedLexeme = R.merge({ @@ -67,19 +67,19 @@ export const equal: IUnboundedLexeme = R.merge({ op === exp ), subType: RelationalOperator.Equal, - regexp: /^(=|eq(\s|$))/i + regexp: /^(=|(eq)(?:\s|$))/i }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, - regexp: /^(>=|ge(\s|$))/i + regexp: /^(>=|(ge)(?:\s|$))/i }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, - regexp: /^(>|gt(\s|$))/i + regexp: /^(>|(gt)(?:\s|$))/i }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = { @@ -100,23 +100,23 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ normalizedOp.indexOf(normalizedExp) === 0; }), subType: RelationalOperator.DateStartsWith, - regexp: /^(datestartswith(\s|$))/i + regexp: /^((datestartswith)(?:\s|$))/i }, LEXEME_BASE); export const lessOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op <= exp), subType: RelationalOperator.LessOrEqual, - regexp: /^(<=|le(\s|$))/i + regexp: /^(<=|(le)(?:\s|$))/i }, LEXEME_BASE); export const lessThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op < exp), subType: RelationalOperator.LessThan, - regexp: /^(<|lt(\s|$))/i + regexp: /^(<|(lt)(?:\s|$))/i }, LEXEME_BASE); export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, - regexp: /^(!=|ne(\s|$))/i + regexp: /^(!=|(ne)(?:\s|$))/i }, LEXEME_BASE); From fafa9c98b2a7ecdf46390d8f2d7249f9034d38d1 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 15:37:39 -0400 Subject: [PATCH 13/16] Revert "Trim filter values." This reverts commit aae4907ec4e757a4751080fdb676bf342a9bfda7. --- src/dash-table/syntax-tree/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-table/syntax-tree/index.ts b/src/dash-table/syntax-tree/index.ts index 89dc5ae04..e4d03607c 100644 --- a/src/dash-table/syntax-tree/index.ts +++ b/src/dash-table/syntax-tree/index.ts @@ -49,9 +49,9 @@ export const getSingleColumnMap = ( } if (s.lexeme.present && s.lexeme.present(s) === RelationalOperator.Equal) { - map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.right.value.trim()}`, column)); + map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.right.value}`, column)); } else { - map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.value.trim()} ${s.right.value.trim()}`, column)); + map.set(sanitizedColumnId, new SingleColumnSyntaxTree(`${s.value} ${s.right.value}`, column)); } } }, statements); From 355be90e0ff68160a331308abb5896617a75c4cc Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 16:31:54 -0400 Subject: [PATCH 14/16] Add regexpMatch parameter for relational operators. --- .../syntax-tree/lexeme/relational.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 1f46abb86..cac7867f5 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -57,7 +57,8 @@ export const contains: IUnboundedLexeme = R.merge({ op.toString().indexOf(exp.toString()) !== -1 ), subType: RelationalOperator.Contains, - regexp: /^((contains)(?:\s|$))/i + regexp: /^((contains)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const equal: IUnboundedLexeme = R.merge({ @@ -67,19 +68,22 @@ export const equal: IUnboundedLexeme = R.merge({ op === exp ), subType: RelationalOperator.Equal, - regexp: /^(=|(eq)(?:\s|$))/i + regexp: /^(=|(eq)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, - regexp: /^(>=|(ge)(?:\s|$))/i + regexp: /^(>=|(ge)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, - regexp: /^(>|(gt)(?:\s|$))/i + regexp: /^(>|(gt)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = { @@ -100,23 +104,27 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ normalizedOp.indexOf(normalizedExp) === 0; }), subType: RelationalOperator.DateStartsWith, - regexp: /^((datestartswith)(?:\s|$))/i + regexp: /^((datestartswith)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const lessOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op <= exp), subType: RelationalOperator.LessOrEqual, - regexp: /^(<=|(le)(?:\s|$))/i + regexp: /^(<=|(le)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const lessThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op < exp), subType: RelationalOperator.LessThan, - regexp: /^(<|(lt)(?:\s|$))/i + regexp: /^(<|(lt)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, - regexp: /^(!=|(ne)(?:\s|$))/i + regexp: /^(!=|(ne)(?:\s|$))/i, + regexpMatch: 2 }, LEXEME_BASE); From f5586187bc1e9f9d909b0aa9bf17f11050ea5bfe Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 18:03:17 -0400 Subject: [PATCH 15/16] Replace non-capturing group with positive lookahead. --- .../syntax-tree/lexeme/relational.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index cac7867f5..05c4814b8 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -57,8 +57,8 @@ export const contains: IUnboundedLexeme = R.merge({ op.toString().indexOf(exp.toString()) !== -1 ), subType: RelationalOperator.Contains, - regexp: /^((contains)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^((contains)(?=\s|$))/i, + regexpMatch: 1 }, LEXEME_BASE); export const equal: IUnboundedLexeme = R.merge({ @@ -68,22 +68,22 @@ export const equal: IUnboundedLexeme = R.merge({ op === exp ), subType: RelationalOperator.Equal, - regexp: /^(=|(eq)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(=|(eq)(?=\s|$))/i, + regexpMatch: 1, }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, - regexp: /^(>=|(ge)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(>=|(ge)(?=\s|$))/i, + regexpMatch: 1, }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, - regexp: /^(>|(gt)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(>|(gt)(?=\s|$))/i, + regexpMatch: 1, }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = { @@ -104,27 +104,27 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({ normalizedOp.indexOf(normalizedExp) === 0; }), subType: RelationalOperator.DateStartsWith, - regexp: /^((datestartswith)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^((datestartswith)(?=\s|$))/i, + regexpMatch: 1 }, LEXEME_BASE); export const lessOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op <= exp), subType: RelationalOperator.LessOrEqual, - regexp: /^(<=|(le)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(<=|(le)(?=\s|$))/i, + regexpMatch: 1 }, LEXEME_BASE); export const lessThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op < exp), subType: RelationalOperator.LessThan, - regexp: /^(<|(lt)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(<|(lt)(?=\s|$))/i, + regexpMatch: 1 }, LEXEME_BASE); export const notEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op !== exp), subType: RelationalOperator.NotEqual, - regexp: /^(!=|(ne)(?:\s|$))/i, - regexpMatch: 2 + regexp: /^(!=|(ne)(?=\s|$))/i, + regexpMatch: 1 }, LEXEME_BASE); From 4a831fa39bd2c3f780e608828e940e24ad01803f Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Mon, 7 Oct 2019 23:29:18 -0400 Subject: [PATCH 16/16] Update relational.ts --- src/dash-table/syntax-tree/lexeme/relational.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dash-table/syntax-tree/lexeme/relational.ts b/src/dash-table/syntax-tree/lexeme/relational.ts index 05c4814b8..bbf354b0a 100644 --- a/src/dash-table/syntax-tree/lexeme/relational.ts +++ b/src/dash-table/syntax-tree/lexeme/relational.ts @@ -69,21 +69,21 @@ export const equal: IUnboundedLexeme = R.merge({ ), subType: RelationalOperator.Equal, regexp: /^(=|(eq)(?=\s|$))/i, - regexpMatch: 1, + regexpMatch: 1 }, LEXEME_BASE); export const greaterOrEqual: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op >= exp), subType: RelationalOperator.GreaterOrEqual, regexp: /^(>=|(ge)(?=\s|$))/i, - regexpMatch: 1, + regexpMatch: 1 }, LEXEME_BASE); export const greaterThan: IUnboundedLexeme = R.merge({ evaluate: relationalEvaluator(([op, exp]) => op > exp), subType: RelationalOperator.GreaterThan, regexp: /^(>|(gt)(?=\s|$))/i, - regexpMatch: 1, + regexpMatch: 1 }, LEXEME_BASE); const DATE_OPTIONS: IDateValidation = {