fix(facebook-custom-audiences): guard against empty normalizePhone() result in getData()#3823
Open
abhandage wants to merge 1 commit into
Open
fix(facebook-custom-audiences): guard against empty normalizePhone() result in getData()#3823abhandage wants to merge 1 commit into
abhandage wants to merge 1 commit into
Conversation
…result in getData() Phone values like '+0000000000' normalize to an empty string after stripping non-numeric chars and leading zeros. processHashing() checks for empty strings before applying the cleaning function but not after, so SmartHashing.hash() would throw 'Cannot hash an empty string' and fail the entire batch. Pre-check normalizePhone() in getData() and short-circuit to '' when the result is empty, matching the existing behavior for other missing/invalid fields. Reproducer: userId ffafc7bd726e4dc9a756333c1b764329, phone +0000000000. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Facebook Custom Audiences sync helper logic to prevent getData() from throwing when a phone number normalizes to an empty string (e.g., +0000000000), and adds a unit test covering that scenario.
Changes:
- Guard phone hashing in
getData()so empty normalized phone values yield''instead of throwing during hashing. - Add a unit test asserting the empty-normalized-phone behavior.
- Apply assorted formatting-only changes in the sync helper module and tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/destination-actions/src/destinations/facebook-custom-audiences/sync/functions.ts |
Adds an empty-normalized-phone guard around phone hashing in getData() (plus formatting). |
packages/destination-actions/src/destinations/facebook-custom-audiences/sync/__tests__/functions.test.ts |
Adds a regression test for the +0000000000 normalization-to-empty case (plus minor formatting). |
Comment on lines
268
to
+270
| externalId ?? '', | ||
| email ? processHashing(email.trim().toLowerCase(), 'sha256', 'hex') : '', | ||
| phone ? processHashing(phone, 'sha256', 'hex', normalizePhone) ?? '' : '', | ||
| phone ? (normalizePhone(phone) ? processHashing(phone, 'sha256', 'hex', normalizePhone) ?? '' : '') : '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
+0000000000) causenormalizePhone()to return an empty string after stripping non-numeric chars and leading zeros.processHashing()guards against empty strings before applying the cleaning function but not after, soSmartHashing.hash()throws'Cannot hash an empty string'and fails the entire batch.normalizePhone()result ingetData()before callingprocessHashing(), short-circuiting to''when the normalized value is empty — consistent with how other missing/invalid fields are handled.Reproducer: line 7992 of test batch (
userId: ffafc7bd726e4dc9a756333c1b764329,phone: +0000000000).Test plan
'returns empty string for phone when it normalizes to an empty string (e.g. "+0000000000")'— assertsrow[2]is''instead of throwing.yarn cloud jest --testPathPattern="facebook-custom-audiences"and confirm all tests pass.getDatatests (email, external ID, DOB normalization, etc.).🤖 Generated with Claude Code