nuxt-og-image 7.1.0 → 7.1.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "nuxt": "^4.6.1 || ^5.0.0-0"
5
5
  },
6
6
  "configKey": "ogImage",
7
- "version": "7.1.0",
7
+ "version": "7.1.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -38,7 +38,7 @@ export async function resolveContext(e) {
38
38
  if (!sigMatch) {
39
39
  return createError({
40
40
  statusCode: 403,
41
- statusMessage: "[Nuxt OG Image] Missing URL signature. Set NUXT_APP_SECRET to sign URLs."
41
+ statusMessage: "[Nuxt OG Image] Missing URL signature. Use the complete image URL."
42
42
  });
43
43
  }
44
44
  const signature = sigMatch[1];
@@ -1,5 +1,6 @@
1
1
  import { digest } from "ohash/crypto";
2
2
  const MAX_PATH_LENGTH = 200;
3
+ const BASE64_CHUNK_SIZE = 8192;
3
4
  const RE_BASE64_PADDING = /=/g;
4
5
  const RE_BASE64_PLUS = /\+/g;
5
6
  const RE_BASE64_SLASH = /\//g;
@@ -9,8 +10,10 @@ const RE_UNDERSCORE = /_/g;
9
10
  const RE_DOUBLE_UNDERSCORE = /__/g;
10
11
  const RE_PERCENT20 = /%20/g;
11
12
  const RE_PLUS = /\+/g;
13
+ const RE_APOSTROPHE = /'/g;
12
14
  const RE_ENCODED_COMMA = /%2c/gi;
13
15
  const RE_ENCODED_PLUS = /%2b/gi;
16
+ const RE_ENCODED_APOSTROPHE = /%27/g;
14
17
  const RE_SINGLE_UNDERSCORE = /(?<!_)_(?!_)/;
15
18
  const RE_OG_PATH_PREFIX = /^\/_og\/[ds]\//;
16
19
  const RE_OG_ROUTE_PREFIX = /\/_og\/[ds]\//;
@@ -18,6 +21,7 @@ const RE_FILE_EXTENSION_WITH_CAPTURE = /\.(\w+)$/;
18
21
  const RE_FILE_EXTENSION = /\.\w+$/;
19
22
  const RE_HASH_SEGMENT = /^o_([a-z0-9]+)$/i;
20
23
  const RE_COMMA_PARAM_SEPARATOR = /,(?=\w+_)/;
24
+ const RE_INLINE_PROP_NAME = /^[a-z0-9]+$/i;
21
25
  const RE_SIGNATURE_SUFFIX = /,s_[^,]+$/;
22
26
  const RE_NON_ASCII = /[^\u0000-\u007F]/;
23
27
  const RE_WINDOWS_RESERVED_FILENAME_CHARACTERS = /[<>:"/\\|?*\u0000-\u001F]/;
@@ -71,7 +75,10 @@ function b64Encode(str) {
71
75
  let encoded;
72
76
  if (typeof btoa === "function") {
73
77
  const utf8 = new TextEncoder().encode(str);
74
- const binary = String.fromCharCode(...utf8);
78
+ let binary = "";
79
+ for (let offset = 0; offset < utf8.length; offset += BASE64_CHUNK_SIZE) {
80
+ binary += String.fromCharCode(...utf8.subarray(offset, offset + BASE64_CHUNK_SIZE));
81
+ }
75
82
  encoded = btoa(binary);
76
83
  } else {
77
84
  encoded = Buffer.from(str, "utf8").toString("base64");
@@ -127,9 +134,10 @@ export function encodeOgImageParams(options, defaults) {
127
134
  for (const [key, value] of Object.entries(options)) {
128
135
  if (key === "props" && typeof value === "object") {
129
136
  for (const [propKey, propValue] of Object.entries(value)) {
130
- if (propValue === void 0 || propValue === null)
137
+ if (propValue === void 0 || propValue === null || propValue === "")
131
138
  continue;
132
- if (typeof propValue === "string" || typeof propValue === "number" || typeof propValue === "boolean") {
139
+ const canEncodeInline = propKey !== "props" && RE_INLINE_PROP_NAME.test(propKey);
140
+ if (canEncodeInline && (typeof propValue === "string" || typeof propValue === "number" || typeof propValue === "boolean")) {
133
141
  flattened[propKey] = propValue;
134
142
  } else {
135
143
  flattened.props = flattened.props || {};
@@ -265,11 +273,11 @@ export function buildOgImageUrl(options, extension = "png", isStatic = false, de
265
273
  const segment = encoded || "default";
266
274
  const signed = secret && !isStatic ? `${segment},s_${signEncodedParams(segment, secret)}` : segment;
267
275
  return {
268
- url: `${prefix}/${signed.replace(/,/g, "%2C").replace(RE_PLUS, "%2B")}.${extension}`
276
+ url: `${prefix}/${signed.replace(/,/g, "%2C").replace(RE_PLUS, "%2B").replace(RE_APOSTROPHE, "%27")}.${extension}`
269
277
  };
270
278
  }
271
279
  function normalizeUrlSegment(segment) {
272
- return segment.replace(RE_ENCODED_COMMA, ",").replace(RE_ENCODED_PLUS, "+");
280
+ return segment.replace(RE_ENCODED_COMMA, ",").replace(RE_ENCODED_PLUS, "+").replace(RE_ENCODED_APOSTROPHE, "'");
273
281
  }
274
282
  export function signEncodedParams(encoded, secret) {
275
283
  return digest(`${secret}:${encoded}`).slice(0, 16);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "7.1.0",
4
+ "version": "7.1.1",
5
5
  "description": "Enlightened OG Image generation for Nuxt.",
6
6
  "author": {
7
7
  "website": "https://harlanzw.com",
@@ -65,8 +65,7 @@
65
65
  "@unocss/core": "^66.11.0",
66
66
  "chrome-launcher": "^1.2.2",
67
67
  "fontless": "^1.3.2",
68
- "nitropack": "^2.13.5",
69
- "nuxt": "^4.6.1 || ^5.0.0",
68
+ "nuxt": "^4.6.1 || ^5.0.0-0",
70
69
  "playwright-core": "^1.64.0",
71
70
  "satori": "^0.47.1",
72
71
  "sharp": "^0.35.5",
@@ -101,9 +100,6 @@
101
100
  "fontless": {
102
101
  "optional": true
103
102
  },
104
- "nitropack": {
105
- "optional": true
106
- },
107
103
  "playwright-core": {
108
104
  "optional": true
109
105
  },