rasti 4.1.0 → 4.1.1-alpha.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.0/docs/logo-dark.svg">
4
- <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.0/docs/logo.svg" height="120">
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.1-alpha.1/docs/logo-dark.svg">
4
+ <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.1-alpha.1/docs/logo.svg" height="120">
5
5
  </picture>
6
6
  </p>
7
7
 
package/dist/rasti.js CHANGED
@@ -1710,6 +1710,26 @@
1710
1710
  return fragment.content;
1711
1711
  }
1712
1712
 
1713
+ /**
1714
+ * Match a name that is legal for an HTML attribute. Excludes whitespace, quotes,
1715
+ * `>`, `/`, `=` and control characters, which would otherwise end the attribute
1716
+ * or the tag when the name is interpolated into markup. An empty name is excluded
1717
+ * as well, since it can't be serialized as a name.
1718
+ * @type {RegExp}
1719
+ * @private
1720
+ */
1721
+ // eslint-disable-next-line no-control-regex
1722
+ const VALID_ATTRIBUTE_NAME = /^[^\s"'>/=\u0000-\u001F\u007F-\u009F]+$/;
1723
+
1724
+ /**
1725
+ * Escape an attribute value. Values are serialized inside double quotes,
1726
+ * so escaping the double quote keeps the value from terminating the attribute.
1727
+ * @param {string} value Attribute value.
1728
+ * @return {string} Escaped attribute value.
1729
+ * @private
1730
+ */
1731
+ const escapeAttributeValue = value => `${value}`.replace(/"/g, '&quot;');
1732
+
1713
1733
  /**
1714
1734
  * Generate HTML string from attributes object.
1715
1735
  * @param {Object} attributes Object containing attribute names and values.
@@ -1722,12 +1742,14 @@
1722
1742
 
1723
1743
  Object.keys(attributes).forEach(key => {
1724
1744
  let value = attributes[key];
1745
+ // Skip invalid names, they can't be serialized as an attribute.
1746
+ if (!VALID_ATTRIBUTE_NAME.test(key)) return;
1725
1747
 
1726
1748
  if (value === true) {
1727
1749
  html.push(key);
1728
1750
  } else if (value !== false) {
1729
1751
  if (value === null || typeof value === 'undefined') value = '';
1730
- html.push(`${key}="${value}"`);
1752
+ html.push(`${key}="${escapeAttributeValue(value)}"`);
1731
1753
  }
1732
1754
  });
1733
1755