diff --git a/package.json b/package.json index 15353500bd..5ef3edd137 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "i18next": "~19.4.0", "i18next-browser-languagedetector": "~4.1.0", "i18next-xhr-backend": "~3.2.2", + "mocha": "~7.1.1", "node-sass": "~4.13.0", "pouchdb": "~7.2.1", "pouchdb-adapter-memory": "~7.2.1", diff --git a/src/__tests__/clients/db/PatientRepository.test.ts b/src/__tests__/clients/db/PatientRepository.test.ts index 1aa405e332..a5ae942af1 100644 --- a/src/__tests__/clients/db/PatientRepository.test.ts +++ b/src/__tests__/clients/db/PatientRepository.test.ts @@ -39,6 +39,15 @@ describe('patient repository', () => { await removeAllDocs() }) + it('should remove all breaking special chars from search text', async () => { + await patients.put({ _id: 'id9999', code: 'P00001', fullName: 'test test' }) + + const result = await PatientRepository.search(']?t}e(s){t** te[\\st') + + expect(result).toHaveLength(1) + expect(result[0].id).toEqual('id9999') + }) + it('should return all records that patient code matches search text', async () => { // same full name to prove that it is finding by patient code const expectedPatientCode = 'P00001' diff --git a/src/clients/db/PatientRepository.ts b/src/clients/db/PatientRepository.ts index e20ce62e95..2b849364f8 100644 --- a/src/clients/db/PatientRepository.ts +++ b/src/clients/db/PatientRepository.ts @@ -13,7 +13,7 @@ export class PatientRepository extends Repository { } async search(text: string): Promise { - const cleanText = text.replace(/[\\[()?*]+/g, '') + const cleanText = text.replace(/[\\[\](){}?*]+/g, '') return super.search({ selector: { $or: [