@acemir/cssom 0.9.8 → 0.9.10

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 CHANGED
@@ -63,7 +63,7 @@ CSSOM.CSSStyleDeclaration.prototype = {
63
63
  {
64
64
  // NOTE: Check viability to add a validation for css values or use a dependency like csstree-validator
65
65
  if (basicStylePropertyValueValidationRegExp.test(value)) {
66
- parseErrorHandler && parseErrorHandler('Invalid CSSStyleDeclaration property value');
66
+ parseErrorHandler && parseErrorHandler('Invalid CSSStyleDeclaration property (name = "' + name + '", value = "' + value + '")');
67
67
  } else if (this[name]) {
68
68
  // Property already exist. Overwrite it.
69
69
  var index = Array.prototype.indexOf.call(this, name);
@@ -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].replace(/^\s+|\s+$/g, "");
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(buffer.trim()).map(function(sel) {
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, spaces) {
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 = "";
@@ -2580,7 +2596,7 @@ CSSOM.parse = function parse(token, errorHandler) {
2580
2596
  if (styleRule === nestedSelectorRule) {
2581
2597
  nestedSelectorRule = null;
2582
2598
  }
2583
- parseError('Invalid CSSStyleRule.selectorText');
2599
+ parseError('Invalid CSSStyleRule (selectorText = "' + styleRule.selectorText + '")');
2584
2600
  } else {
2585
2601
  currentScope.cssRules.push(styleRule);
2586
2602
  }
@@ -64,7 +64,7 @@ CSSOM.CSSStyleDeclaration.prototype = {
64
64
  {
65
65
  // NOTE: Check viability to add a validation for css values or use a dependency like csstree-validator
66
66
  if (basicStylePropertyValueValidationRegExp.test(value)) {
67
- parseErrorHandler && parseErrorHandler('Invalid CSSStyleDeclaration property value');
67
+ parseErrorHandler && parseErrorHandler('Invalid CSSStyleDeclaration property (name = "' + name + '", value = "' + value + '")');
68
68
  } else if (this[name]) {
69
69
  // Property already exist. Overwrite it.
70
70
  var index = Array.prototype.indexOf.call(this, name);
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].replace(/^\s+|\s+$/g, "");
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(buffer.trim()).map(function(sel) {
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, spaces) {
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 = "";
@@ -999,7 +1015,7 @@ CSSOM.parse = function parse(token, errorHandler) {
999
1015
  if (styleRule === nestedSelectorRule) {
1000
1016
  nestedSelectorRule = null;
1001
1017
  }
1002
- parseError('Invalid CSSStyleRule.selectorText');
1018
+ parseError('Invalid CSSStyleRule (selectorText = "' + styleRule.selectorText + '")');
1003
1019
  } else {
1004
1020
  currentScope.cssRules.push(styleRule);
1005
1021
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "parser",
8
8
  "styleSheet"
9
9
  ],
10
- "version": "0.9.8",
10
+ "version": "0.9.10",
11
11
  "author": "Nikita Vasilyev <me@elv1s.ru>",
12
12
  "contributors": [
13
13
  "Acemir Sousa Mendes <acemirsm@gmail.com>"