Skip to content

Commit 174552b

Browse files
committed
BUG#29795595: allow leading and trailing whitespaces in expressions
The X DevAPI expression parser is pretty strict when it comes to leading and trailing whitespaces in an expression string. These extra characters do not have any special meaning and do not cause any particular harm. This patch relaxes this behavior and updates the expression parser to allow extra leading and trailing whitespaces in expression strings. Change-Id: I74d279e5db323c420c8cb4ff42b5831842c1b4a1
1 parent dcb79f7 commit 174552b

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

lib/ExprParser/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
const Parser = require('./lib/index.js');
3434

3535
function parse (expr, options) {
36-
return Parser(Object.assign({}, options, { input: expr })).tryParse(expr);
36+
return Parser(Object.assign({}, options, { input: expr }))
37+
// We can drop any leading or trailing whitespace from the input
38+
// expression string.
39+
.tryParse(expr.trim());
3740
}
3841

3942
module.exports = { parse, Mode: Parser.Mode, Type: Parser.Type };

test/unit/ExprParser/expr.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,58 +43,47 @@ const assertIgnoredWhitespaces = (expr) => {
4343

4444
describe('ExprParser', () => {
4545
context('expr', () => {
46-
// TODO(Rui): BUG#29795595
47-
it.skip('ignores any leading or trailing whitespace in an intervalExpr', () => {
46+
it('ignores any leading or trailing whitespace in an intervalExpr', () => {
4847
return assertIgnoredWhitespaces('CURTIME() + INTERVAL 2 HOUR');
4948
});
5049

51-
// TODO(Rui): BUG#29795595
52-
it.skip('ignores any leading or trailing whitespace in a mulDivExpr', () => {
50+
it('ignores any leading or trailing whitespace in a mulDivExpr', () => {
5351
return assertIgnoredWhitespaces('2 * 4');
5452
});
5553

56-
// TODO(Rui): BUG#29795595
57-
it.skip('ignores any leading or trailing whitespace in a addSubExpr', () => {
54+
it('ignores any leading or trailing whitespace in a addSubExpr', () => {
5855
return assertIgnoredWhitespaces('1 + 1');
5956
});
6057

61-
// TODO(Rui): BUG#29795595
62-
it.skip('ignores any leading or trailing whitespace in a shiftExpr', () => {
58+
it('ignores any leading or trailing whitespace in a shiftExpr', () => {
6359
return assertIgnoredWhitespaces('2 >> 1');
6460
});
6561

66-
// TODO(Rui): BUG#29795595
67-
it.skip('ignores any leading or trailing whitespace in a bitExpr', () => {
62+
it('ignores any leading or trailing whitespace in a bitExpr', () => {
6863
return assertIgnoredWhitespaces('1 ^ 1');
6964
});
7065

71-
// TODO(Rui): BUG#29795595
72-
it.skip('ignores any leading or trailing whitespace in a shiftExpr', () => {
66+
it('ignores any leading or trailing whitespace in a shiftExpr', () => {
7367
return assertIgnoredWhitespaces('2 >> 1');
7468
});
7569

76-
// TODO(Rui): BUG#29795595
77-
it.skip('ignores any leading or trailing whitespace in a compExpr', () => {
70+
it('ignores any leading or trailing whitespace in a compExpr', () => {
7871
return assertIgnoredWhitespaces('foo = :v');
7972
});
8073

81-
// TODO(Rui): BUG#29795595
82-
it.skip('ignores any leading or trailing whitespace in a shiftExpr', () => {
74+
it('ignores any leading or trailing whitespace in a shiftExpr', () => {
8375
return assertIgnoredWhitespaces('2 >> 1');
8476
});
8577

86-
// TODO(Rui): BUG#29795595
87-
it.skip('ignores any leading or trailing whitespace in an ilriExpr', () => {
78+
it('ignores any leading or trailing whitespace in an ilriExpr', () => {
8879
return assertIgnoredWhitespaces('TRUE IS NOT FALSE');
8980
});
9081

91-
// TODO(Rui): BUG#29795595
92-
it.skip('ignores any leading or trailing whitespace in an andExpr', () => {
82+
it('ignores any leading or trailing whitespace in an andExpr', () => {
9383
return assertIgnoredWhitespaces('foo = "bar" AND baz = "qux"');
9484
});
9585

96-
// TODO(Rui): BUG#29795595
97-
it.skip('ignores any leading or trailing whitespace in an orExpr', () => {
86+
it('ignores any leading or trailing whitespace in an orExpr', () => {
9887
return assertIgnoredWhitespaces('foo = "bar" OR baz = "qux"');
9988
});
10089

0 commit comments

Comments
 (0)