@zubra/runtime 5.9.1 → 5.10.0

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.
@@ -5,6 +5,11 @@
5
5
  import { $r, isSafeSrcset, isSafeUrl } from './element.js';
6
6
  import { effect } from './effect.js';
7
7
 
8
+ // The names a spread may write, as the server checks them: XML's attribute names, and CSS
9
+ // property names (custom ones included).
10
+ const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_.:-]*$/;
11
+ const CSS_PROPERTY = /^(?:--[A-Za-z0-9_-]+|[A-Za-z][A-Za-z0-9-]*)$/;
12
+
8
13
  const see = (section) => ` (see https://github.com/journey-to-code-org/zubra#${section})`;
9
14
 
10
15
  // ---- {...spread}: an object's entries as attributes, properties and listeners --------------
@@ -80,6 +85,12 @@ export function spread(part, node) {
80
85
  console.error(`zubra: a spread can't set "${key}"${see('safety')}`);
81
86
  continue;
82
87
  }
88
+ // A key from a value (maybe a user's) that can't be an attribute name: left out, as the
89
+ // server leaves it out of the HTML.
90
+ if (!ATTRIBUTE_NAME.test(name)) {
91
+ console.error(`zubra: a spread's key isn't an attribute name, so it was left out${see('safety')}:`, key);
92
+ continue;
93
+ }
83
94
  if (name === 'class') {
84
95
  nextClasses = String(value ?? '').split(/\s+/).filter(Boolean);
85
96
  continue;
@@ -92,6 +103,10 @@ export function spread(part, node) {
92
103
  }
93
104
  for (const [property, propertyValue] of Object.entries(value)) {
94
105
  const css = kebab(property);
106
+ if (!CSS_PROPERTY.test(css)) {
107
+ console.error(`zubra: a spread's style key isn't a CSS property name, so it was left out${see('safety')}:`, property);
108
+ continue;
109
+ }
95
110
  if (own.has(`style:${css}`)) continue;
96
111
  if (propertyValue == null || propertyValue === false) continue;
97
112
  nextStyles.add(css);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/runtime",
3
- "version": "5.9.1",
3
+ "version": "5.10.0",
4
4
  "description": "Browser runtime for Zubra compiled components, built on the TC39 Signals API",
5
5
  "license": "ISC",
6
6
  "repository": {
package/src/spread.js CHANGED
@@ -4,6 +4,11 @@
4
4
  import { $r, isSafeSrcset, isSafeUrl } from './element.js';
5
5
  import { effect } from './effect.js';
6
6
 
7
+ // The names a spread may write, as the server checks them: XML's attribute names, and CSS
8
+ // property names (custom ones included).
9
+ const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_.:-]*$/;
10
+ const CSS_PROPERTY = /^(?:--[A-Za-z0-9_-]+|[A-Za-z][A-Za-z0-9-]*)$/;
11
+
7
12
  const see = (section) => ` (see https://github.com/journey-to-code-org/zubra#${section})`;
8
13
 
9
14
  // ---- {...spread}: an object's entries as attributes, properties and listeners --------------
@@ -79,6 +84,12 @@ export function spread(part, node) {
79
84
  console.error(`zubra: a spread can't set "${key}"${see('safety')}`);
80
85
  continue;
81
86
  }
87
+ // A key from a value (maybe a user's) that can't be an attribute name: left out, as the
88
+ // server leaves it out of the HTML.
89
+ if (!ATTRIBUTE_NAME.test(name)) {
90
+ console.error(`zubra: a spread's key isn't an attribute name, so it was left out${see('safety')}:`, key);
91
+ continue;
92
+ }
82
93
  if (name === 'class') {
83
94
  nextClasses = String(value ?? '').split(/\s+/).filter(Boolean);
84
95
  continue;
@@ -91,6 +102,10 @@ export function spread(part, node) {
91
102
  }
92
103
  for (const [property, propertyValue] of Object.entries(value)) {
93
104
  const css = kebab(property);
105
+ if (!CSS_PROPERTY.test(css)) {
106
+ console.error(`zubra: a spread's style key isn't a CSS property name, so it was left out${see('safety')}:`, property);
107
+ continue;
108
+ }
94
109
  if (own.has(`style:${css}`)) continue;
95
110
  if (propertyValue == null || propertyValue === false) continue;
96
111
  nextStyles.add(css);