Skip to content

Commit

Permalink
Some more fixes regarding numbers ending with a decimal mark (like `2…
Browse files Browse the repository at this point in the history
….`). See josdejong#711.
  • Loading branch information
josdejong committed Sep 20, 2016
1 parent 68c3475 commit 7742b36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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];
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/expression/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7742b36

Please sign in to comment.