@@ -181,7 +181,7 @@ async function do_query(req, genomeobj) {
181181 const categories = req . query . categories || null
182182 const __isgene = req . query . __isgene
183183
184- const items = await getBEDitems ( req , genomeobj , flag_gm , gmisoform )
184+ const items = filterItems ( await getBEDitems ( req , genomeobj , flag_gm , gmisoform ) , req )
185185
186186 if ( req . query . getdata ) {
187187 ///////////////////////// exit ///////////////////
@@ -860,6 +860,7 @@ async function getBEDitems(req, genomeobj, flag_gm, gmisoform) {
860860 if ( ! Array . isArray ( req . query . bedItems ) ) throw 'bedItems not array'
861861 const lst = [ ]
862862 for ( const j of req . query . bedItems ) {
863+ if ( ! j ) continue
863864 if ( typeof j != 'object' ) throw 'one of bedItems[] not obj'
864865 if ( ! j . chr ) throw 'bedItems[].chr missing'
865866 if ( ! Number . isInteger ( j . start ) ) throw 'bedItems[].start not integer'
@@ -875,6 +876,12 @@ async function getBEDitems(req, genomeobj, flag_gm, gmisoform) {
875876 }
876877 if ( j . rglst . length == 0 ) continue
877878 lst . push ( j )
879+ if ( lst . length > 1000 ) {
880+ console . error (
881+ 'will not process over 1000 items from req.query.bedItems to guard against arbitrarily large array from client'
882+ )
883+ break
884+ }
878885 }
879886 return lst
880887 }
@@ -891,41 +898,44 @@ async function getBEDitems(req, genomeobj, flag_gm, gmisoform) {
891898 }
892899
893900 const regionitems = await query_file ( req . query , tkfile , dir , flag_gm , gmisoform )
901+ const items = [ ]
902+ for ( const lst of regionitems ) {
903+ for ( const i of lst ) items . push ( i )
904+ }
905+ return items
906+ }
894907
908+ function filterItems ( _items , req ) {
895909 let filterByName
896910 if ( req . query . filterByName ) {
897911 filterByName = new Set ( req . query . filterByName . split ( / [ \s \n ] / ) . map ( i => i . trim ( ) ) )
898912 }
899-
900913 const items = [ ]
901914
902- // apply filtering
903- for ( const lst of regionitems ) {
904- for ( const i of lst ) {
905- if ( req . query . usevalue ) {
906- const v = i [ req . query . usevalue . key ]
907- if ( ! Number . isFinite ( v ) ) {
908- continue
909- }
910- if ( req . query . usevalue . dropBelowCutoff && v < req . query . usevalue . dropBelowCutoff ) {
911- continue
912- }
915+ for ( const i of _items ) {
916+ if ( req . query . usevalue ) {
917+ const v = i [ req . query . usevalue . key ]
918+ if ( ! Number . isFinite ( v ) ) {
919+ continue
913920 }
914- if ( req . query . bplengthUpperLimit && i . stop - i . start > req . query . bplengthUpperLimit ) {
921+ if ( req . query . usevalue . dropBelowCutoff && v < req . query . usevalue . dropBelowCutoff ) {
915922 continue
916923 }
917- if ( filterByName ) {
918- if ( i . isoform ) {
919- if ( ! filterByName . has ( i . isoform ) ) continue
920- } else if ( i . name ) {
921- if ( ! filterByName . has ( i . name ) ) continue
922- } else {
923- // do not show nameless items in this case
924- continue
925- }
924+ }
925+ if ( req . query . bplengthUpperLimit && i . stop - i . start > req . query . bplengthUpperLimit ) {
926+ continue
927+ }
928+ if ( filterByName ) {
929+ if ( i . isoform ) {
930+ if ( ! filterByName . has ( i . isoform ) ) continue
931+ } else if ( i . name ) {
932+ if ( ! filterByName . has ( i . name ) ) continue
933+ } else {
934+ // do not show nameless items in this case
935+ continue
926936 }
927- items . push ( i )
928937 }
938+ items . push ( i )
929939 }
930940 return items
931941}
0 commit comments