fix(vue): fix regular expressions catastrophic backtracking

This commit is contained in:
zoomchan-cxj
2022-09-14 10:43:06 +08:00
committed by Zoom Chan
parent 55174ed472
commit 1fe30eda6c
3 changed files with 5 additions and 5 deletions
@@ -122,7 +122,7 @@ function convertToDegree(value: string, unit = DEGREE_UNIT.DEG): string {
*/
function getLinearGradientAngle(value: string): string | undefined {
const processedValue = (value || '').replace(/\s*/g, '').toLowerCase();
const reg = /^([+-]?\d+\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const reg = /^([+-]?(?=(?<digit>\d+))\k<digit>\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const valueList = reg.exec(processedValue);
if (!Array.isArray(valueList)) return;
// default direction is to bottom, i.e. 180degree
@@ -61,7 +61,7 @@ const commentRegexp = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
* Trim `str`.
*/
function trim(str) {
return str ? str.replace(/^\s+|\s+$/g, '') : '';
return str ? str.trim() : '';
}
@@ -297,7 +297,7 @@ function parseCSS(css, options) {
/* @fix Remove all comments from selectors
* http://ostermiller.org/findcomment.html */
return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/\/\*(?=(?<digit1>([^*]|[\r\n]|((?=(?<digit2>\*+))\k<digit2>([^*/]|[\r\n])))*))\k<digit1>\*\/+/g, '')
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, m => m.replace(/,/g, '\u200C'))
.split(/\s*(?![^(]*\)),\s*/)
.map(s => s.replace(/\u200C/g, ','));
@@ -335,7 +335,7 @@ function parseCSS(css, options) {
*/
function getLinearGradientAngle(value) {
const processedValue = (value || '').replace(/\s*/g, '').toLowerCase();
const reg = /^([+-]?\d+\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const reg = /^([+-]?(?=(?<digit>\d+))\k<digit>\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const valueList = reg.exec(processedValue);
if (!Array.isArray(valueList)) return;
// default direction is to bottom, i.e. 180degree
@@ -92,7 +92,7 @@ function convertToDegree(value, unit = DEGREE_UNIT.DEG) {
*/
function getLinearGradientAngle(value) {
const processedValue = (value || '').replace(/\s*/g, '').toLowerCase();
const reg = /^([+-]?\d+\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const reg = /^([+-]?(?=(?<digit>\d+))\k<digit>\.?\d*)+(deg|turn|rad)|(to\w+)$/g;
const valueList = reg.exec(processedValue);
if (!Array.isArray(valueList)) return;
// if default direction is to bottom, i.e. 180degree