File tree Expand file tree Collapse file tree 1 file changed +25
-8
lines changed
flagsmith-engine/segments Expand file tree Collapse file tree 1 file changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -90,18 +90,35 @@ export class SegmentConditionModel {
9090 ) ;
9191 } ,
9292 evaluateRegex : ( traitValue : any ) => {
93- return (
94- ! ! this . value &&
95- ! ! traitValue ?. toString ( ) . match ( new RegExp ( this . value ?. toString ( ) ) )
96- ) ;
93+ try {
94+ if ( ! this . value ) {
95+ return false ;
96+ }
97+ const regex = new RegExp ( this . value ?. toString ( ) ) ;
98+ return ! ! traitValue ?. toString ( ) . match ( regex ) ;
99+ } catch {
100+ return false ;
101+ }
97102 } ,
98103 evaluateModulo : ( traitValue : any ) => {
99- if ( isNaN ( parseFloat ( traitValue ) ) || ! this . value ) {
104+ const parsedTraitValue = parseFloat ( traitValue ) ;
105+ if ( isNaN ( parsedTraitValue ) || ! this . value ) {
100106 return false ;
101107 }
102- const parts = this . value ?. toString ( ) . split ( '|' ) ;
103- const [ divisor , reminder ] = [ parseFloat ( parts [ 0 ] ) , parseFloat ( parts [ 1 ] ) ] ;
104- return traitValue % divisor === reminder ;
108+
109+ const parts = this . value . toString ( ) . split ( '|' ) ;
110+ if ( parts . length !== 2 ) {
111+ return false ;
112+ }
113+
114+ const divisor = parseFloat ( parts [ 0 ] ) ;
115+ const remainder = parseFloat ( parts [ 1 ] ) ;
116+
117+ if ( isNaN ( divisor ) || isNaN ( remainder ) || divisor === 0 ) {
118+ return false ;
119+ }
120+
121+ return parsedTraitValue % divisor === remainder ;
105122 } ,
106123 evaluateIn : ( traitValue : string [ ] | string ) => {
107124 if ( Array . isArray ( this . value ) ) {
You can’t perform that action at this time.
0 commit comments