@symbiotejs/symbiote 3.5.5 → 3.5.7

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/node/SSR.js CHANGED
@@ -41,6 +41,30 @@ function extractCSS(sheet) {
41
41
  return text;
42
42
  }
43
43
 
44
+ /**
45
+ * Check if a node is inside a <pre> or <code> ancestor.
46
+ * @param {Node} node
47
+ * @returns {boolean}
48
+ */
49
+ function isInsidePreformatted(node) {
50
+ let el = node.parentElement;
51
+ while (el) {
52
+ let tag = el.localName;
53
+ if (tag === 'pre' || tag === 'code') return true;
54
+ el = el.parentElement;
55
+ }
56
+ return false;
57
+ }
58
+
59
+ /**
60
+ * Escape HTML special characters in text content.
61
+ * @param {string} text
62
+ * @returns {string}
63
+ */
64
+ function escapeHtml(text) {
65
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
66
+ }
67
+
44
68
  /**
45
69
  * Resolve {{prop}} text node tokens by reading values from the closest custom element.
46
70
  * @param {string} text
@@ -146,8 +170,9 @@ function serializeAttrs(el) {
146
170
  * @returns {string}
147
171
  */
148
172
  function serializeNode(node, emittedStyles, nonce) {
149
- // Custom element — recurse:
150
- if (node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
173
+ let preformatted = isInsidePreformatted(node);
174
+ // Custom element recurse (skip inside pre/code):
175
+ if (!preformatted && node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
151
176
  return serializeElement(/** @type {HTMLElement} */ (node), emittedStyles, nonce);
152
177
  }
153
178
  // Regular element:
@@ -162,7 +187,8 @@ function serializeNode(node, emittedStyles, nonce) {
162
187
  }
163
188
  // Text node:
164
189
  if (node.nodeType === 3) {
165
- return resolveTextTokens(node.textContent || '', node);
190
+ if (preformatted) return escapeHtml(node.textContent || '');
191
+ return resolveTextTokens(escapeHtml(node.textContent || ''), node);
166
192
  }
167
193
  // Comment:
168
194
  if (node.nodeType === 8) {
@@ -233,7 +259,9 @@ async function* streamElement(el, emittedStyles, nonce) {
233
259
  * @returns {AsyncGenerator<string>}
234
260
  */
235
261
  async function* streamNode(node, emittedStyles, nonce) {
236
- if (node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
262
+ let preformatted = isInsidePreformatted(node);
263
+ // Custom element — stream (skip inside pre/code):
264
+ if (!preformatted && node.nodeType === 1 && /** @type {Element} */ (node).localName?.includes('-')) {
237
265
  yield* streamElement(/** @type {HTMLElement} */ (node), emittedStyles, nonce);
238
266
  return;
239
267
  }
@@ -252,7 +280,11 @@ async function* streamNode(node, emittedStyles, nonce) {
252
280
  return;
253
281
  }
254
282
  if (node.nodeType === 3) {
255
- yield resolveTextTokens(node.textContent || '', node);
283
+ if (preformatted) {
284
+ yield escapeHtml(node.textContent || '');
285
+ } else {
286
+ yield resolveTextTokens(escapeHtml(node.textContent || ''), node);
287
+ }
256
288
  return;
257
289
  }
258
290
  if (node.nodeType === 8) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@symbiotejs/symbiote",
4
- "version": "3.5.5",
4
+ "version": "3.5.7",
5
5
  "description": "Symbiote.js - zero-dependency close-to-platform frontend library to build super-powered web components",
6
6
  "author": "team@rnd-pro.com",
7
7
  "license": "MIT",
@@ -1 +1 @@
1
- {"version":3,"file":"SSR.d.ts","sourceRoot":"","sources":["../../node/SSR.js"],"names":[],"mappings":"AAsQA;IAEE,8BAAmB;IACnB,8BAAmB;IAMnB;;;OAkEC;IAMD,uBAYC;IAkBD,yBAZW,MAAM,YACN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,OAAO,CAAC,MAAM,CAAC,CAgC3B;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,MAAM,CAwBlB;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,cAAc,CAAC,MAAM,CAAC,CAqBlC;CACF"}
1
+ {"version":3,"file":"SSR.d.ts","sourceRoot":"","sources":["../../node/SSR.js"],"names":[],"mappings":"AAsSA;IAEE,8BAAmB;IACnB,8BAAmB;IAMnB;;;OAkEC;IAMD,uBAYC;IAkBD,yBAZW,MAAM,YACN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,OAAO,CAAC,MAAM,CAAC,CAgC3B;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,MAAM,CAwBlB;IAWD,+BALW,MAAM;;iBAEN;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChB,cAAc,CAAC,MAAM,CAAC,CAqBlC;CACF"}