Skip to content

fix(facebook-custom-audiences): guard against empty normalizePhone() result in getData()#3823

Open
abhandage wants to merge 1 commit into
mainfrom
fix/facebook-custom-audiences-empty-phone-hash
Open

fix(facebook-custom-audiences): guard against empty normalizePhone() result in getData()#3823
abhandage wants to merge 1 commit into
mainfrom
fix/facebook-custom-audiences-empty-phone-hash

Conversation

@abhandage

Copy link
Copy Markdown
Contributor

Summary

  • Phone values consisting entirely of zeros (e.g. +0000000000) cause normalizePhone() 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, so SmartHashing.hash() throws 'Cannot hash an empty string' and fails the entire batch.
  • Fix: pre-check the normalizePhone() result in getData() before calling processHashing(), 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

  • New unit test added: 'returns empty string for phone when it normalizes to an empty string (e.g. "+0000000000")' — asserts row[2] is '' instead of throwing.
  • Run yarn cloud jest --testPathPattern="facebook-custom-audiences" and confirm all tests pass.
  • Confirm no regression in existing getData tests (email, external ID, DOB normalization, etc.).

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings June 4, 2026 14:17
@abhandage abhandage requested a review from a team as a code owner June 4, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) ?? '' : '') : '',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants