Skip to content

Commit

Permalink
Better balance check
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Jun 28, 2022
1 parent 2792bb4 commit 5110e42
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,17 +1057,27 @@ export const directiveSanitizer = (args) => {
for (let i = 0; i < kArr.length; i++) {
const k = kArr[i];
const val = args.themeVariables[k];
if (!val.match(/^[a-zA-Z0-9#,";()%. ]+$/)) {
if (val && val.match && !val.match(/^[a-zA-Z0-9#,";()%. ]+$/)) {
args.themeVariables[k] = '';
}
}
}
log.debug('After sanitization', args);
};
export const sanitizeCss = (str) => {
const stringsearch = 'o';
const startCnt = (str.match(/\{/g) || []).length;
const endCnt = (str.match(/\}/g) || []).length;
let startCnt = 0;
let endCnt = 0;

for (let i = 0; i < str.length; i++) {
if (startCnt < endCnt) {
return '{ /* ERROR: Unbalanced CSS */ }';
}
if (str[i] === '{') {
startCnt++;
} else if (str[i] === '}') {
endCnt++;
}
}
if (startCnt !== endCnt) {
return '{ /* ERROR: Unbalanced CSS */ }';
}
Expand Down

0 comments on commit 5110e42

Please sign in to comment.