File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ function reduceCSSCalc(value, decimalPrecision) {
6666 }
6767
6868 // Remove units in expression:
69- var toEvaluate = expression . replace ( new RegExp ( unit , "g " ) , "" )
69+ var toEvaluate = expression . replace ( new RegExp ( unit , "gi " ) , "" )
7070 var result
7171
7272 try {
@@ -134,16 +134,18 @@ function reduceCSSCalc(value, decimalPrecision) {
134134
135135function getUnitsInExpression ( expression ) {
136136 var uniqueUnits = [ ]
137- var unitRegEx = / [ \. 0 - 9 ] ( [ % a - z ] + ) / g
137+ var uniqueLowerCaseUnits = [ ]
138+ var unitRegEx = / [ \. 0 - 9 ] ( [ % a - z ] + ) / gi
138139 var matches = unitRegEx . exec ( expression )
139140
140141 while ( matches ) {
141142 if ( ! matches || ! matches [ 1 ] ) {
142143 continue
143144 }
144145
145- if ( uniqueUnits . indexOf ( matches [ 1 ] ) === - 1 ) {
146+ if ( uniqueLowerCaseUnits . indexOf ( matches [ 1 ] . toLowerCase ( ) ) === - 1 ) {
146147 uniqueUnits . push ( matches [ 1 ] )
148+ uniqueLowerCaseUnits . push ( matches [ 1 ] . toLowerCase ( ) )
147149 }
148150
149151 matches = unitRegEx . exec ( expression )
Original file line number Diff line number Diff line change @@ -104,3 +104,12 @@ test("ignore unrecognized values", function(t) {
104104
105105 t . end ( )
106106} )
107+
108+ test ( "non-lowercase units" , function ( t ) {
109+ t . equal ( reduceCSSCalc ( "calc(1PX)" ) , "1PX" , "all uppercase" ) ;
110+ t . equal ( reduceCSSCalc ( "calc(1Px)" ) , "1Px" , "first letter uppercase" ) ;
111+ t . equal ( reduceCSSCalc ( "calc(50% - 42Px)" ) , "calc(50% - 42Px)" , "preserves percentage" ) ;
112+ t . equal ( reduceCSSCalc ( "calc(1Px + 1pX)" ) , "2Px" , "combines same units mixed case" ) ;
113+
114+ t . end ( )
115+ } )
You can’t perform that action at this time.
0 commit comments