From 415e80b97744d10a58f1b8e1ddd32cddc5f9a702 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2020 15:58:02 +0000 Subject: [PATCH 1/3] chore(deps-dev): bump lint-staged from 10.1.7 to 10.2.0 Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.1.7 to 10.2.0. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](https://github.com/okonet/lint-staged/compare/v10.1.7...v10.2.0) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af0a8e1e58..b893d576b6 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "history": "~4.10.1", "husky": "~4.2.1", "jest": "~24.9.0", - "lint-staged": "~10.1.0", + "lint-staged": "~10.2.0", "memdown": "~5.1.0", "prettier": "~2.0.4", "redux-mock-store": "~1.5.4", From 9e6eaba2bc5f749893b27744444aaba114d00806 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:53:48 +0000 Subject: [PATCH 2/3] chore(deps): bump uuid from 7.0.3 to 8.0.0 Bumps [uuid](https://github.com/uuidjs/uuid) from 7.0.3 to 8.0.0. - [Release notes](https://github.com/uuidjs/uuid/releases) - [Changelog](https://github.com/uuidjs/uuid/blob/master/CHANGELOG.md) - [Commits](https://github.com/uuidjs/uuid/compare/v7.0.3...v8.0.0) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b893d576b6..793b81ee1e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "redux-thunk": "~2.3.0", "shortid": "^2.2.15", "typescript": "~3.8.2", - "uuid": "^7.0.1" + "uuid": "^8.0.0" }, "repository": { "type": "git", From 1693e5f542b7bead83dd0495b2fb2dc4398b3319 Mon Sep 17 00:00:00 2001 From: John Darke <52716187+JDarke@users.noreply.github.com> Date: Fri, 1 May 2020 00:20:04 +0100 Subject: [PATCH 3/3] fix(patients): fixes search when using special characters (#2012) --- package.json | 1 + .../clients/db/PatientRepository.test.ts | 9 +++++++++ src/clients/db/PatientRepository.ts | 4 +++- src/components/Sidebar.tsx | 18 ++++++++---------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 793b81ee1e..c23dd474ec 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@types/pouchdb-find": "~6.3.4", "bootstrap": "~4.4.1", "date-fns": "~2.12.0", + "escape-string-regexp": "~4.0.0", "i18next": "~19.4.0", "i18next-browser-languagedetector": "~4.1.0", "i18next-xhr-backend": "~3.2.2", diff --git a/src/__tests__/clients/db/PatientRepository.test.ts b/src/__tests__/clients/db/PatientRepository.test.ts index 1aa405e332..e45cd7262b 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 escape all special chars from search text', async () => { + await patients.put({ _id: 'id9999', code: 'P00001', fullName: 'test -]?}(){*[\\$+.^test' }) + + const result = await PatientRepository.search('test -]?}(){*[\\$+.^test') + + 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 5fb5937ed0..99a239685e 100644 --- a/src/clients/db/PatientRepository.ts +++ b/src/clients/db/PatientRepository.ts @@ -1,3 +1,4 @@ +import escapeStringRegexp from 'escape-string-regexp' import shortid from 'shortid' import Patient from '../../model/Patient' import Repository from './Repository' @@ -13,12 +14,13 @@ export class PatientRepository extends Repository { } async search(text: string): Promise { + const escapedString = escapeStringRegexp(text) return super.search({ selector: { $or: [ { fullName: { - $regex: RegExp(text, 'i'), + $regex: RegExp(escapedString, 'i'), }, }, { diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index d4ed204d4f..e70dfcd5e3 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -55,22 +55,20 @@ const Sidebar = () => { cursor: 'pointer', fontSize: 'small', borderBottomWidth: 0, - color: - (splittedPath[1].includes('patients') || splittedPath[1].includes('appointments')) && - splittedPath.length > 2 - ? 'white' - : 'black', + borderTopWidth: 0, + color: 'black', + padding: '.6rem 1.25rem', + backgroundColor: 'rgba(245,245,245,1)', } const listSubItemStyle: CSSProperties = { cursor: 'pointer', fontSize: 'small', borderBottomWidth: 0, - color: - (splittedPath[1].includes('patients') || splittedPath[1].includes('appointments')) && - splittedPath.length < 3 - ? 'white' - : 'black', + borderTopWidth: 0, + color: 'black', + padding: '.6rem 1.25rem', + backgroundColor: 'rgba(245,245,245,1)', } const getDashboardLink = () => (