fix(contacts): encode the contact id or email in the request path

Draft
LA
1d ago
+105-52

Problem

The contact methods put the contact id or email into the URL path as it is. An email can contain characters that mean something else in a URL.

  • With a#b@example.com, everything after # is dropped. The request goes to /contacts/a and the API answers with an invalid id error.
  • ? starts a query string, and / splits the path.

The Contacts API is starting to accept more valid addresses, like a&b@example.com, a#b@example.com and a=b@example.com. Lookups by email need to work for them.

Fix

The contact id or email now goes through encodeURIComponent before it is added to the path. Suppressions, inboxes and events already do this.

It covers these methods.

  • contacts.get, contacts.update and contacts.remove, with and without audienceId.
  • contacts.topics.list and contacts.topics.update.
  • contacts.segments.list, contacts.segments.add and contacts.segments.remove.

Note on the recordings

@ is now sent as %40. The API reads both the same way. The recorded integration tests match on the exact URL, so six recordings are updated by hand to the encoded URL and its request id. The recorded responses are not changed. They were not recorded again against the live API.

How it was verified

A new spec checks the encoded URL for each method with a#b@example.com. The full test suite passes, 817 tests. Lint and typecheck pass.


Summary by cubic

Contact identifiers are now encoded with encodeURIComponent when added to the request path, so lookups by email work for addresses containing URL-sensitive characters. Previously, characters like #, ?, /, &, and = could truncate or split the path and cause the request to fail.

All contact methods now encode the identifier: get, update, and remove (with and without audienceId), plus topics and segments.

  • @ is now sent as %40; the API reads both the same way. Six recording URLs and their request IDs were updated by hand; recorded responses are unchanged.
  • A new spec verifies the encoded URL for each method using a#b@example.com.