Skip to content

Scheduling infrastructure for absolutely everyone.

Escape special characters in email query (#25079)

Joe Au-Yeung5267f8c3c171
diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts
index 447b6603e4a..eee5716ec16 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) {