@@ -25,7 +25,12 @@ function patchWalkPath(target: any, path: string) {
2525
2626 for ( let i = 0 ; i < segments . length - 1 ; i ++ ) {
2727 const key = segments [ i ] ;
28- if ( ! ( key in current ) ) {
28+ if ( Array . isArray ( current ) ) {
29+ const idx = parseInt ( key , 10 ) ;
30+ if ( isNaN ( idx ) || idx < 0 || idx >= current . length ) {
31+ throw new UniversalApiError ( "PATCH body request malformed" , "ERROR" , "" , Constants . HTTP_STATUS_CODE . BAD_REQUEST ) ;
32+ }
33+ } else if ( typeof current !== "object" || current === null || ! ( key in current ) ) {
2934 throw new UniversalApiError ( "PATCH body request malformed" , "ERROR" , "" , Constants . HTTP_STATUS_CODE . BAD_REQUEST ) ;
3035 }
3136 current = current [ key ] ;
@@ -444,6 +449,10 @@ export const Utils = {
444449 } ,
445450 async parseRequest ( request : UniversalApiRequest < any > , res : ServerResponse , fullUrl : URL , parserRequest : UniversalApiParser , logger : ILogger ) {
446451 try {
452+ if ( request . body !== null || request . files !== null || request . readableEnded ) {
453+ logger . debug ( "parseRequest: skipped (already parsed or stream ended)" ) ;
454+ return ;
455+ }
447456 if ( parserRequest ) {
448457 logger . debug ( "parseRequest: START" ) ;
449458 if ( typeof parserRequest === "object" ) {
@@ -670,8 +679,10 @@ export const Utils = {
670679 }
671680 try {
672681 await next ( error ) ;
673- if ( lastError && ! res . writableEnded ) {
674- throw lastError ;
682+ if ( lastError ) {
683+ if ( ! res . writableEnded ) {
684+ throw lastError ;
685+ }
675686 }
676687 } catch ( finalError : any ) {
677688 throw new UniversalApiError ( finalError , "ERROR_MIDDLEWARE" , "" , Constants . HTTP_STATUS_CODE . INTERNAL_SERVER_ERROR ) ;
@@ -692,8 +703,8 @@ export const Utils = {
692703 hasPaginationOrFilters ( method : UniversalApiRequest < any > [ "method" ] , paginationPlugin : UniversalApiOptionsRequired [ "pagination" ] , filterPlugin : UniversalApiOptionsRequired [ "filters" ] , paginationHandler : UniversalApiRestFsHandler [ "pagination" ] , filtersHandler : UniversalApiRestFsHandler [ "filters" ] ) {
693704 return ( ! ! paginationHandler && paginationHandler !== "none" )
694705 || ( ! ! filtersHandler && filtersHandler !== "none" )
695- || ( paginationPlugin !== null && ( method ! in paginationPlugin || "ALL" in paginationPlugin ) )
696- || ( filterPlugin !== null && ( method ! in filterPlugin || "ALL" in filterPlugin ) )
706+ || ( paginationPlugin != null && ( method ! in paginationPlugin || "ALL" in paginationPlugin ) )
707+ || ( filterPlugin != null && ( method ! in filterPlugin || "ALL" in filterPlugin ) )
697708 } ,
698709 getPaginationAndFilters ( request : UniversalApiRequest < any > , paginationHandler : UniversalApiRestFsHandler [ "pagination" ] , filtersHandler : UniversalApiRestFsHandler [ "filters" ] , paginationPlugin : UniversalApiOptions [ "pagination" ] , filtersPlugin : UniversalApiOptions [ "filters" ] ) : { pagination : null | { limit : null | number , skip : null | number , sort : null | string , order : null | string } , filters : null | { key : string , value : any , comparison : string , regexFlags ?: string } [ ] } {
699710 const result : { pagination : null | { limit : null | number , skip : null | number , sort : null | string , order : null | string } , filters : null | { key : string , value : any , comparison : string , regexFlags ?: string } [ ] } = {
@@ -1235,7 +1246,6 @@ export const Utils = {
12351246 res . statusCode = data . status ;
12361247 data . headers . forEach ( ( { name, value } ) => res . setHeader ( name , value ) ) ;
12371248 res . setHeader ( "content-length" , size ) ;
1238- data . headers . push ( { name : "content-length" , value : size } ) ;
12391249 const stream = createReadStream ( data . data ) ;
12401250
12411251 const cleanup = ( err ?: Error ) => {
0 commit comments