From 5267f8c3c17188b10750618bfb35dfe48434e01b Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Tue, 11 Nov 2025 18:56:51 -0500 Subject: [PATCH] Escape special characters in email query (#25079) --- packages/app-store/salesforce/lib/CrmService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts index 447b6603e4..eee5716ec1 100644 --- a/packages/app-store/salesforce/lib/CrmService.ts +++ b/packages/app-store/salesforce/lib/CrmService.ts @@ -553,8 +553,11 @@ export default class SalesforceCRMService implements CRM { setFallbackToContact?: boolean; conn: Connection; }) { + // Escape SOSL reserved characters: ? & | ! { } [ ] ( ) ^ ~ * : \ " ' + - + // eslint-disable-next-line no-useless-escape + const escapedEmail = email.replace(/([?&|!{}[\]()^~*:\\"'+\-])/g, "\\$1"); const searchResult = await conn.search( - `FIND {${email}} IN EMAIL FIELDS RETURNING Lead(Id, Email, OwnerId, Owner.Email), Contact(Id, Email, OwnerId, Owner.Email)` + `FIND {${escapedEmail}} IN EMAIL FIELDS RETURNING Lead(Id, Email, OwnerId, Owner.Email), Contact(Id, Email, OwnerId, Owner.Email)` ); if (searchResult.searchRecords.length === 0) {