diff --git a/CHANGELOG.md b/CHANGELOG.md index cf74bd2466c..b4926ab6bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Bump AGP to v8.3.1 - Bump desugar JDK library to v2.0.4 +### Fixes + +- Fix app crash on searching overdue patient with special characters + ## 2024-01-08-8979 ### Internal diff --git a/app/src/main/java/org/simple/clinic/overdue/AppointmentRepository.kt b/app/src/main/java/org/simple/clinic/overdue/AppointmentRepository.kt index 79f7ed1d558..61291e23566 100644 --- a/app/src/main/java/org/simple/clinic/overdue/AppointmentRepository.kt +++ b/app/src/main/java/org/simple/clinic/overdue/AppointmentRepository.kt @@ -152,8 +152,16 @@ class AppointmentRepository @Inject constructor( ) } - private fun transformSearchInputsIntoQuery(searchInputs: List) = searchInputs - .joinToString(separator = " OR ") { "*$it*" } + private fun transformSearchInputsIntoQuery(searchInputs: List): String { + return searchInputs.joinToString(separator = " OR ") { + sanitizeSearchQuery(it) + } + } + + private fun sanitizeSearchQuery(query: String): String { + val escapedQuery = query.replace(Regex.fromLiteral("\""), "\"\"") + return "\"*$escapedQuery*\"" + } fun lastCreatedAppointmentForPatient(patientUuid: UUID): Optional { return appointmentDao.lastCreatedAppointmentForPatient(patientUuid).toOptional()