Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/modules/QueryBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,20 @@ describe('QueryBuilder', () => {
})
).toThrow(QueryBuilderErrors.INVALID_REGEX)
})
it('should not throw an error if regex string is invalid if validateRegex is false', () => {
expect(
builder.build({
operator: EvaluationQueryOperatorEnum.REGEX,
value: '[',
field: foobar,
validateRegex: false,
})
).toEqual({
foobar: {
[EvaluationQueryOperatorEnum.REGEX]: '[',
},
})
})
it('simple test', () => {
expect(
builder.build({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class QueryBuilder {
if (typeof filter.value !== 'string')
throw new Error(QueryBuilderErrors.NOT_A_STRING)
// throw error if regex is invalid
if (!isValidRegex(filter.value))
if (filter.validateRegex !== false && !isValidRegex(filter.value))
throw new Error(QueryBuilderErrors.INVALID_REGEX)
return {
[filter.field]: {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ export type EvaluationFilter = {
field: string
operator: EvaluationQueryOperatorEnum.REGEX
value: string
validateRegex?: boolean
}

export type QueryBuilderQuery =
Expand Down
Loading