diff --git a/HISTORY.md b/HISTORY.md index eea16f401b..2b7d98ab95 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,11 @@ # History +## not yet released, version 3.5.3 + +- Some more fixes regarding numbers ending with a decimal mark (like `2.`). + + ## 2016-09-20, version 3.5.2 - Fixed numbers ending with a decimal mark (like `2.`) not being supported by diff --git a/lib/expression/parse.js b/lib/expression/parse.js index ca40823061..176e774630 100644 --- a/lib/expression/parse.js +++ b/lib/expression/parse.js @@ -208,7 +208,6 @@ function factory (type, config, load, typed) { // skip over whitespaces // space, tab, and newline when inside parameters while (isWhitespace(c)) { - // TODO: also take '\r' carriage return as newline? Or does that give problems on mac? next(); } @@ -424,18 +423,19 @@ function factory (type, config, load, typed) { * @private */ function isWhitespace (c) { - return c == ' ' || c == '\t' || (c == '\n' && nesting_level > 0) + // TODO: also take '\r' carriage return as newline? Or does that give problems on mac? + return c == ' ' || c == '\t' || (c == '\n' && nesting_level > 0); } /** * Test whether the character c is a decimal mark (dot). - * This depends on whether it's followed by a digit or whitespace + * This is the case when it's not the start of a delimeter like '.*' or './' * @param {string} c * @param {string} cNext * @return {boolean} */ function isDecimalMark (c, cNext) { - return c == '.' && (isDigit(cNext) || isWhitespace(cNext) || cNext == '') + return c == '.' && !DELIMITERS[c + cNext]; } /** diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js index ca12da8d88..e0a1da6e33 100644 --- a/test/expression/parse.test.js +++ b/test/expression/parse.test.js @@ -1001,6 +1001,7 @@ describe('parse', function() { it('should parse add +', function() { assert.equal(parseAndEval('2 + 3'), 5); assert.equal(parseAndEval('2 + 3 + 4'), 9); + assert.equal(parseAndEval('2.+3'), 5); // test whether the decimal mark isn't confused }); it('should parse divide /', function() {