Skip to content

Commit 594e2e6

Browse files
committed
Restore deleted input validation helpers
1 parent 5e36948 commit 594e2e6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/common/src/utils/input.validation.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,26 @@ const sanitize = (obj) => {
375375

376376
module.exports.sanitize = sanitize;
377377

378+
module.exports.sanitizeObjectId = (value) => {
379+
if (typeof value !== "string") return null;
380+
const normalized = value.trim();
381+
if (!normalized) return null;
382+
return mongoose.Types.ObjectId.isValid(normalized) ? normalized : null;
383+
};
384+
385+
module.exports.sanitizeNonEmptyString = (value, options = {}) => {
386+
if (typeof value !== "string") return null;
387+
388+
const { maxLength = 1024, allowNullByte = false } = options;
389+
const normalized = value.trim();
390+
391+
if (!normalized) return null;
392+
if (normalized.length > maxLength) return null;
393+
if (!allowNullByte && normalized.includes("\0")) return null;
394+
395+
return normalized;
396+
};
397+
378398
const emptyToUndefined = z.preprocess(
379399
(val) => (val === "" || val === null ? undefined : val),
380400
z.string().optional(),

0 commit comments

Comments
 (0)