unhead 1.8.4 → 1.8.6

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/dist/index.cjs CHANGED
@@ -259,6 +259,22 @@ const TitleTemplatePlugin = shared.defineHeadPlugin({
259
259
  }
260
260
  });
261
261
 
262
+ const XSSPlugin = shared.defineHeadPlugin({
263
+ hooks: {
264
+ "tags:afterResolve": function(ctx) {
265
+ for (const tag of ctx.tags) {
266
+ if (typeof tag.innerHTML === "string") {
267
+ if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type)) {
268
+ tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
269
+ } else {
270
+ tag.innerHTML = tag.innerHTML.replace(new RegExp(`</${tag.tag}`, "g"), `<\\/${tag.tag}`);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+ });
277
+
262
278
  let activeHead;
263
279
  // @__NO_SIDE_EFFECTS__
264
280
  function createHead(options = {}) {
@@ -345,6 +361,7 @@ function createHeadCore(options = {}) {
345
361
  }
346
362
  await hooks.callHook("tags:beforeResolve", resolveCtx);
347
363
  await hooks.callHook("tags:resolve", resolveCtx);
364
+ await hooks.callHook("tags:afterResolve", resolveCtx);
348
365
  return resolveCtx.tags;
349
366
  },
350
367
  ssr
@@ -357,6 +374,7 @@ function createHeadCore(options = {}) {
357
374
  SortPlugin,
358
375
  TemplateParamsPlugin,
359
376
  TitleTemplatePlugin,
377
+ XSSPlugin,
360
378
  ...options?.plugins || []
361
379
  ].forEach((p) => head.use(p));
362
380
  head.hooks.callHook("init", head);
package/dist/index.mjs CHANGED
@@ -258,6 +258,22 @@ const TitleTemplatePlugin = defineHeadPlugin({
258
258
  }
259
259
  });
260
260
 
261
+ const XSSPlugin = defineHeadPlugin({
262
+ hooks: {
263
+ "tags:afterResolve": function(ctx) {
264
+ for (const tag of ctx.tags) {
265
+ if (typeof tag.innerHTML === "string") {
266
+ if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type)) {
267
+ tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
268
+ } else {
269
+ tag.innerHTML = tag.innerHTML.replace(new RegExp(`</${tag.tag}`, "g"), `<\\/${tag.tag}`);
270
+ }
271
+ }
272
+ }
273
+ }
274
+ }
275
+ });
276
+
261
277
  let activeHead;
262
278
  // @__NO_SIDE_EFFECTS__
263
279
  function createHead(options = {}) {
@@ -344,6 +360,7 @@ function createHeadCore(options = {}) {
344
360
  }
345
361
  await hooks.callHook("tags:beforeResolve", resolveCtx);
346
362
  await hooks.callHook("tags:resolve", resolveCtx);
363
+ await hooks.callHook("tags:afterResolve", resolveCtx);
347
364
  return resolveCtx.tags;
348
365
  },
349
366
  ssr
@@ -356,6 +373,7 @@ function createHeadCore(options = {}) {
356
373
  SortPlugin,
357
374
  TemplateParamsPlugin,
358
375
  TitleTemplatePlugin,
376
+ XSSPlugin,
359
377
  ...options?.plugins || []
360
378
  ].forEach((p) => head.use(p));
361
379
  head.hooks.callHook("init", head);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unhead",
3
3
  "type": "module",
4
- "version": "1.8.4",
4
+ "version": "1.8.6",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -30,9 +30,9 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "hookable": "^5.5.3",
33
- "@unhead/dom": "1.8.4",
34
- "@unhead/schema": "1.8.4",
35
- "@unhead/shared": "1.8.4"
33
+ "@unhead/schema": "1.8.6",
34
+ "@unhead/shared": "1.8.6",
35
+ "@unhead/dom": "1.8.6"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "unbuild .",