site-panzai/node_modules/@nuxt/nitro-server/dist/runtime/utils/island-props.mjs
2026-11-13 13:57:04 +01:00

42 lines
832 B
JavaScript

export const MAX_ISLAND_BODY_BYTES = 64 * 1024;
export const MAX_ISLAND_PROP_DEPTH = 64;
export function exceedsMaxDepth(raw, maxDepth = MAX_ISLAND_PROP_DEPTH) {
let depth = 0;
let inString = false;
let escaped = false;
for (let i = 0; i < raw.length; i++) {
const ch = raw[i];
if (inString) {
if (escaped) {
escaped = false;
} else if (ch === "\\") {
escaped = true;
} else if (ch === "\"") {
inString = false;
}
continue;
}
if (ch === "\"") {
inString = true;
} else if (ch === "{" || ch === "[") {
if (++depth > maxDepth) {
return true;
}
} else if (ch === "}" || ch === "]") {
if (depth > 0) {
depth--;
}
}
}
return false;
}
export function exceedsMaxBytes(raw, maxBytes = MAX_ISLAND_BODY_BYTES) {
return Buffer.byteLength(raw, "utf8") > maxBytes;
}