Skip to content

Commit 57a5ce1

Browse files
Handle null traits for regex evaluations (#152)
1 parent 9cbbbaf commit 57a5ce1

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

flagsmith-engine/segments/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class SegmentConditionModel {
6969
!traitValue.includes(this.value?.toString());
7070
},
7171
evaluateRegex: (traitValue: any) => {
72-
return !!this.value && !!traitValue.match(new RegExp(this.value));
72+
return !!this.value && !!traitValue?.toString().match(new RegExp(this.value));
7373
},
7474
evaluateModulo: (traitValue: any) => {
7575
if (isNaN(parseFloat(traitValue)) || !this.value) {

tests/engine/unit/segments/segments_model.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const conditionMatchCases: [string, string | number | boolean | null, string, bo
6464
[CONDITION_OPERATORS.NOT_CONTAINS, null, 'foo', false],
6565
[CONDITION_OPERATORS.REGEX, 'foo', '[a-z]+', true],
6666
[CONDITION_OPERATORS.REGEX, 'FOO', '[a-z]+', false],
67+
[CONDITION_OPERATORS.REGEX, null, '[a-z]+', false],
6768
[CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.0:semver", true],
6869
[CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.0:semver", true],
6970
[CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.1:semver", false],

0 commit comments

Comments
 (0)