fix(contacts): encode the contact id or email in the request path
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/aand 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 ERB::Util.url_encode before it is added to the path. Suppressions and inboxes already do this.
It covers these methods.
Resend::Contacts.get,updateandremove, with and withoutaudience_id.Resend::Contacts::Topics.listandupdate.Resend::Contacts::Segments.list,addandremove.
@ is now sent as %40. The API reads both the same way.
How it was verified
New specs check the encoded path for each method with a#b@example.com. The full suite passes, 502 examples. Rubocop passes.
Same fix as resend/resend-node#1217.
Summary by cubic
Fixes contact lookups by email when the address contains URL-significant characters like #, ?, /, &, or =.
Previously, an email such as a#b@example.com would be truncated at the #, sending the request to /contacts/a and returning an invalid id error. Contact identifiers are now URL-encoded before being added to the path, matching the behavior of suppressions and inboxes. The API accepts the encoded form (%40 for @) the same as the raw value.
- Applies encoding to
Contacts.get,update, andremove(with and withoutaudience_id),Topics.listandupdate, andSegments.list,add, andremove. - Adds specs that verify the encoded path for each method using
a#b@example.com.
Same fix as resend/resend-node#1217.