Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore calc() in length-zero-no-unit #4175

Merged
merged 12 commits into from Aug 11, 2019
8 changes: 6 additions & 2 deletions lib/utils/getMathFunctionsRanges.js
@@ -1,12 +1,16 @@
"use strict";

const MATH_REGEXP = /calc\([^()]*(?:\(.*\))*[^()]*\)/gi;
const MATH_FUNCTIONS = ["calc"];
const MATH_FUNCTIONS_REGEXP = new RegExp(
`(?:${MATH_FUNCTIONS.join("|")})` + "\\([^()]*(?:\\(.*\\))*[^()]*\\)",
"gi"
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use regexp for this cases, we have postcss-value-parser, regexp is slow and unsafe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


module.exports = function getMathFunctionsRanges(valueString) {
const result = [];
let current;

while ((current = MATH_REGEXP.exec(valueString)) !== null) {
while ((current = MATH_FUNCTIONS_REGEXP.exec(valueString)) !== null) {
result.push([current.index, current.index + current[0].length]);
}

Expand Down