@acemir/cssom 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/CSSOM.js +20 -4
- package/lib/parse.js +20 -4
- package/package.json +1 -1
package/build/CSSOM.js
CHANGED
|
@@ -2037,10 +2037,19 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2037
2037
|
* @returns {boolean} Returns true if all selectors are valid, otherwise false.
|
|
2038
2038
|
*/
|
|
2039
2039
|
function isValidSelectorText(selectorText) {
|
|
2040
|
+
// Check for newlines inside single or double quotes using regex
|
|
2041
|
+
// This matches any quoted string (single or double) containing a newline
|
|
2042
|
+
var quotedNewlineRegExp = /(['"])(?:\\.|[^\\])*?\1/g;
|
|
2043
|
+
var match;
|
|
2044
|
+
while ((match = quotedNewlineRegExp.exec(selectorText)) !== null) {
|
|
2045
|
+
if (/\r|\n/.test(match[0].slice(1, -1))) {
|
|
2046
|
+
return false;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2040
2049
|
// Split selectorText by commas and validate each part
|
|
2041
2050
|
var selectors = parseAndSplitNestedSelectors(selectorText);
|
|
2042
2051
|
for (var i = 0; i < selectors.length; i++) {
|
|
2043
|
-
var processedSelectors = selectors[i].
|
|
2052
|
+
var processedSelectors = selectors[i].trim();
|
|
2044
2053
|
if (!validateSelector(processedSelectors)) {
|
|
2045
2054
|
return false;
|
|
2046
2055
|
}
|
|
@@ -2276,7 +2285,10 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2276
2285
|
}
|
|
2277
2286
|
|
|
2278
2287
|
currentScope = parentRule = styleRule;
|
|
2279
|
-
styleRule.selectorText = buffer.trim()
|
|
2288
|
+
styleRule.selectorText = buffer.trim().replace(/(['"])(?:\\.|[^\\])*?\1|(\r\n|\r|\n)/g, function(match, _, newline) {
|
|
2289
|
+
if (newline) return " ";
|
|
2290
|
+
return match;
|
|
2291
|
+
});
|
|
2280
2292
|
styleRule.style.__starts = i;
|
|
2281
2293
|
styleRule.parentStyleSheet = styleSheet;
|
|
2282
2294
|
buffer = "";
|
|
@@ -2411,8 +2423,12 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2411
2423
|
}
|
|
2412
2424
|
|
|
2413
2425
|
styleRule = new CSSOM.CSSStyleRule();
|
|
2426
|
+
var processedSelectorText = buffer.trim().replace(/(['"])(?:\\.|[^\\])*?\1|(\r\n|\r|\n)/g, function(match, _, newline) {
|
|
2427
|
+
if (newline) return " ";
|
|
2428
|
+
return match;
|
|
2429
|
+
});
|
|
2414
2430
|
// In a nested selector, ensure each selector contains '&' at the beginning, except for selectors that already have '&' somewhere
|
|
2415
|
-
styleRule.selectorText = parseAndSplitNestedSelectors(
|
|
2431
|
+
styleRule.selectorText = parseAndSplitNestedSelectors(processedSelectorText).map(function(sel) {
|
|
2416
2432
|
return sel.indexOf('&') === -1 ? '& ' + sel : sel;
|
|
2417
2433
|
}).join(', ');
|
|
2418
2434
|
styleRule.style.__starts = i - buffer.length;
|
|
@@ -2546,7 +2562,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2546
2562
|
case "}":
|
|
2547
2563
|
if (state === "counterStyleBlock") {
|
|
2548
2564
|
// FIXME : Implement cssText get setter that parses the real implementation
|
|
2549
|
-
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote
|
|
2565
|
+
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote) {
|
|
2550
2566
|
return quote ? match : ' ';
|
|
2551
2567
|
}) + " }";
|
|
2552
2568
|
buffer = "";
|
package/lib/parse.js
CHANGED
|
@@ -456,10 +456,19 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
456
456
|
* @returns {boolean} Returns true if all selectors are valid, otherwise false.
|
|
457
457
|
*/
|
|
458
458
|
function isValidSelectorText(selectorText) {
|
|
459
|
+
// Check for newlines inside single or double quotes using regex
|
|
460
|
+
// This matches any quoted string (single or double) containing a newline
|
|
461
|
+
var quotedNewlineRegExp = /(['"])(?:\\.|[^\\])*?\1/g;
|
|
462
|
+
var match;
|
|
463
|
+
while ((match = quotedNewlineRegExp.exec(selectorText)) !== null) {
|
|
464
|
+
if (/\r|\n/.test(match[0].slice(1, -1))) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
459
468
|
// Split selectorText by commas and validate each part
|
|
460
469
|
var selectors = parseAndSplitNestedSelectors(selectorText);
|
|
461
470
|
for (var i = 0; i < selectors.length; i++) {
|
|
462
|
-
var processedSelectors = selectors[i].
|
|
471
|
+
var processedSelectors = selectors[i].trim();
|
|
463
472
|
if (!validateSelector(processedSelectors)) {
|
|
464
473
|
return false;
|
|
465
474
|
}
|
|
@@ -695,7 +704,10 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
695
704
|
}
|
|
696
705
|
|
|
697
706
|
currentScope = parentRule = styleRule;
|
|
698
|
-
styleRule.selectorText = buffer.trim()
|
|
707
|
+
styleRule.selectorText = buffer.trim().replace(/(['"])(?:\\.|[^\\])*?\1|(\r\n|\r|\n)/g, function(match, _, newline) {
|
|
708
|
+
if (newline) return " ";
|
|
709
|
+
return match;
|
|
710
|
+
});
|
|
699
711
|
styleRule.style.__starts = i;
|
|
700
712
|
styleRule.parentStyleSheet = styleSheet;
|
|
701
713
|
buffer = "";
|
|
@@ -830,8 +842,12 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
830
842
|
}
|
|
831
843
|
|
|
832
844
|
styleRule = new CSSOM.CSSStyleRule();
|
|
845
|
+
var processedSelectorText = buffer.trim().replace(/(['"])(?:\\.|[^\\])*?\1|(\r\n|\r|\n)/g, function(match, _, newline) {
|
|
846
|
+
if (newline) return " ";
|
|
847
|
+
return match;
|
|
848
|
+
});
|
|
833
849
|
// In a nested selector, ensure each selector contains '&' at the beginning, except for selectors that already have '&' somewhere
|
|
834
|
-
styleRule.selectorText = parseAndSplitNestedSelectors(
|
|
850
|
+
styleRule.selectorText = parseAndSplitNestedSelectors(processedSelectorText).map(function(sel) {
|
|
835
851
|
return sel.indexOf('&') === -1 ? '& ' + sel : sel;
|
|
836
852
|
}).join(', ');
|
|
837
853
|
styleRule.style.__starts = i - buffer.length;
|
|
@@ -965,7 +981,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
965
981
|
case "}":
|
|
966
982
|
if (state === "counterStyleBlock") {
|
|
967
983
|
// FIXME : Implement cssText get setter that parses the real implementation
|
|
968
|
-
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote
|
|
984
|
+
counterStyleRule.cssText = "@counter-style " + counterStyleRule.name + " { " + buffer.trim().replace(/\n/g, " ").replace(/(['"])(?:\\.|[^\\])*?\1|(\s{2,})/g, function(match, quote) {
|
|
969
985
|
return quote ? match : ' ';
|
|
970
986
|
}) + " }";
|
|
971
987
|
buffer = "";
|