Skip to content

Commit 3ec89b5

Browse files
committed
Fixed: regression from 1.2.5 on calc() on multiple lines
1 parent 449f5d2 commit 3ec89b5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Fixed: regression from 1.2.5 on calc() on multiple lines
2+
(@MoOx)
3+
14
# 1.2.5 - 2016-08-20
25

36
- Fixed: security issue due to the usage of ``eval()``.

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ function reduceCSSCalc(value, decimalPrecision) {
3232
stack = 0
3333
decimalPrecision = Math.pow(10, decimalPrecision === undefined ? 5 : decimalPrecision)
3434

35-
// CSS allow to omit 0 for 0.* values,
36-
// but math-expression-evaluator does not
37-
value = value.replace(/\s(\.[0-9])/g, " 0$1")
35+
value = value
36+
// CSS allow to omit 0 for 0.* values,
37+
// but math-expression-evaluator does not
38+
.replace(/\s(\.[0-9])/g, " 0$1")
39+
40+
// allow calc() on multiple lines
41+
.replace(/\n+/g, " ")
3842

3943
/**
4044
* Evaluates an expression

test/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,8 @@ test("non-lowercase units", function(t) {
117117

118118
t.end()
119119
})
120+
121+
test("should handle calc() on multiple lines", function(t) {
122+
t.equal(reduceCSSCalc("calc(\n\n 1 +\n 1\n\n)"), "2", "addition")
123+
t.end()
124+
})

0 commit comments

Comments
 (0)