MCPcopy Index your code
hub / github.com/ether/etherpad / validatePluginValue

Function validatePluginValue

src/node/db/Pad.ts:66–83  ·  view source on GitHub ↗
(
    key: string, value: unknown, maxBytes: number)

Source from the content-addressed store, hash-verified

64// most `maxBytes` UTF-8 bytes. Returns the serialized length on success so
65// callers can enforce a cumulative cap without serializing twice.
66const validatePluginValue = (
67 key: string, value: unknown, maxBytes: number): {ok: true, bytes: number} | {ok: false, reason: string} => {
68 let serialized: string;
69 try {
70 serialized = JSON.stringify(value);
71 } catch (e: any) {
72 return {ok: false, reason: `JSON.stringify failed: ${e && e.message || e}`};
73 }
74 if (serialized === undefined) {
75 // JSON.stringify returns undefined for top-level functions/undefined.
76 return {ok: false, reason: 'value is not JSON-serializable (function/undefined)'};
77 }
78 const bytes = Buffer.byteLength(serialized, 'utf8');
79 if (bytes > maxBytes) {
80 return {ok: false, reason: `serialized size ${bytes}B exceeds per-key cap ${maxBytes}B`};
81 }
82 return {ok: true, bytes};
83};
84
85/**
86 * Copied from the Etherpad source code. It converts Windows line breaks to Unix

Callers 1

normalizePadSettingsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected