Skip to content

Commit

Permalink
fix(fabric.parser): attempt to resolve some issues with regexp (fabri…
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored and rockerBOO committed Jan 12, 2022
1 parent 12b0519 commit 14a2bee
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,22 +1001,26 @@
if (styleContents.trim() === '') {
continue;
}
rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g);
rules = rules.map(function(rule) { return rule.trim(); });
// recovers all the rule in this form `body { style code... }`
// rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g);
rules = styleContents.split('}');
// remove empty rules.
rules = rules.filter(function(rule) { return rule.trim(); });
// at this point we have hopefully an array of rules `body { style code... `
// eslint-disable-next-line no-loop-func
rules.forEach(function(rule) {

var match = rule.match(/([\s\S]*?)\s*\{([^}]*)\}/),
ruleObj = { }, declaration = match[2].trim(),
propertyValuePairs = declaration.replace(/;$/, '').split(/\s*;\s*/);
var match = rule.split('{'),
ruleObj = { }, declaration = match[1].trim(),
propertyValuePairs = declaration.split(';').filter(function(pair) { return pair.trim(); });

for (i = 0, len = propertyValuePairs.length; i < len; i++) {
var pair = propertyValuePairs[i].split(/\s*:\s*/),
property = pair[0],
value = pair[1];
var pair = propertyValuePairs[i].split(':'),
property = pair[0].trim(),
value = pair[1].trim();
ruleObj[property] = value;
}
rule = match[1];
rule = match[0].trim();
rule.split(',').forEach(function(_rule) {
_rule = _rule.replace(/^svg/i, '').trim();
if (_rule === '') {
Expand Down

0 comments on commit 14a2bee

Please sign in to comment.