diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b63382..2ebbc747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,3 +30,4 @@ * [UIPQB-48](https://issues.folio.org/browse/UIPQB-48) "Show columns" dropdown doesn't fit in the screen. * [UIPQB-47](https://issues.folio.org/browse/UIPQB-47) 400 error blocks save or further action in query builder. * [UIPQB-51](https://issues.folio.org/browse/UIPQB-51) Dropdown typeahead should use contains not starts with. +* [UIPQB-55](https://issues.folio.org/browse/UIPQB-55) Regular expressions are incorrect for contains and starts_with operators diff --git a/src/QueryBuilder/QueryBuilder/helpers/query.js b/src/QueryBuilder/QueryBuilder/helpers/query.js index 62d6ac68..56c4db2c 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/query.js +++ b/src/QueryBuilder/QueryBuilder/helpers/query.js @@ -47,7 +47,7 @@ export const sourceToMongoQuery = (source) => { const escapeRegex = (value) => { const escapedValue = value.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&'); - return `^${escapedValue}`; + return `${escapedValue}`; }; source.forEach((item) => { diff --git a/src/QueryBuilder/QueryBuilder/helpers/query.test.js b/src/QueryBuilder/QueryBuilder/helpers/query.test.js index f961e655..0ca75e03 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/query.test.js +++ b/src/QueryBuilder/QueryBuilder/helpers/query.test.js @@ -59,12 +59,6 @@ describe('mongoQueryToSource()', () => { operator: { options: expect.any(Array), current: OPERATORS.CONTAINS }, value: { current: 'abc' }, }, - { - boolean: { options: booleanOptions, current: 'AND' }, - field: { options: fieldOptions, current: 'user_full_name' }, - operator: { options: expect.any(Array), current: OPERATORS.CONTAINS }, - value: { current: 'abc' }, - }, { boolean: { options: booleanOptions, current: 'AND' }, field: { options: fieldOptions, current: 'languages' }, @@ -82,7 +76,6 @@ describe('mongoQueryToSource()', () => { { user_last_name: { $gte: 'value' } }, { languages: { $in: ['value', 'value2'] } }, { user_full_name: { $regex: 'abc' } }, - { user_full_name: { $regex: 'abc' } }, { languages: { $nin: ['value', 'value2'] } }, ], }; @@ -122,8 +115,7 @@ describe('mongoQueryToSource()', () => { { user_last_name: { $lt: 10 } }, { user_last_name: { $gte: 'value' } }, { languages: { $in: ['value', 'value2'] } }, - { user_full_name: { $regex: '^abc' } }, - { user_full_name: { $regex: '^abc' } }, + { user_full_name: { $regex: 'abc' } }, { languages: { $nin: ['value', 'value2'] } }, ], };