Skip to content

Commit 2dbf9e7

Browse files
committed
Fixed: regression from 1.2.5 on calc() with value without leading 0
1 parent 8c76f2f commit 2dbf9e7

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Fixed: regression from 1.2.5 on calc() with value without leading 0
2+
(@MoOx)
3+
14
# 1.2.6 - 2016-08-22
25

36
- Fixed: regression from 1.2.5 on calc() on multiple lines

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function reduceCSSCalc(value, decimalPrecision) {
3535
value = value
3636
// CSS allow to omit 0 for 0.* values,
3737
// but math-expression-evaluator does not
38-
.replace(/\s(\.[0-9])/g, " 0$1")
38+
.replace(/(\s|\()(\.[0-9])/g, "$10$2")
3939

4040
// allow calc() on multiple lines
4141
.replace(/\n+/g, " ")

test/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ test("should handle calc() on multiple lines", function(t) {
122122
t.equal(reduceCSSCalc("calc(\n\n 1 +\n 1\n\n)"), "2", "addition")
123123
t.end()
124124
})
125+
126+
test("should handle calc() with values without leading 0", function(t) {
127+
t.equal(reduceCSSCalc("calc(.1 + .1 + 1.1 + 0.2)"), "1.5", "addition")
128+
t.end()
129+
})

0 commit comments

Comments
 (0)