File tree Expand file tree Collapse file tree
packages/common/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -375,6 +375,26 @@ const sanitize = (obj) => {
375375
376376module . 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+
378398const emptyToUndefined = z . preprocess (
379399 ( val ) => ( val === "" || val === null ? undefined : val ) ,
380400 z . string ( ) . optional ( ) ,
You can’t perform that action at this time.
0 commit comments