Skip to content

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

Draft
LauraBeatris wants to merge 1 commit into
mainfrom
fix/encode-contact-identifier-in-path
Draft

LauraBeatris wants to merge 1 commit into
mainfrom
fix/encode-contact-identifier-in-path

Conversation

@LauraBeatris

@LauraBeatris LauraBeatris commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

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 ERB::Util.url_encode before it is added to the path. Suppressions and inboxes already do this.

It covers these methods.

  • Resend::Contacts.get, update and remove, with and without audience_id.
  • Resend::Contacts::Topics.list and update.
  • Resend::Contacts::Segments.list, add and remove.

@ 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, and remove (with and without audience_id), Topics.list and update, and Segments.list, add, and remove.
  • Adds specs that verify the encoded path for each method using a#b@example.com.

Same fix as resend/resend-node#1217.

Written for commit d7a3d78. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 4 files

Confidence score: 4/5

  • spec/contacts_spec.rb has six new spec descriptions using should, which violates the repo’s test-naming rule. Rename them declaratively.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="spec/contacts_spec.rb">

<violation number="1" location="spec/contacts_spec.rb:425">
P2: Custom agent: **No `should` in tests**

Six newly added specs use `should` in their descriptions, which this repo's test-naming rule prohibits. Rename them declaratively, e.g. "url encodes the email when getting a contact", "url encodes the email when removing a contact", "url encodes the email when updating a contact", "url encodes the email in an audience-scoped path", "url encodes the email in topics paths", and "url encodes the email in segments paths".</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread spec/contacts_spec.rb
allow_any_instance_of(Resend::Request).to receive(:perform).and_return({})
end

it "should url encode the email when getting a contact" do

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.

P2: Custom agent: No should in tests

Six newly added specs use should in their descriptions, which this repo's test-naming rule prohibits. Rename them declaratively, e.g. "url encodes the email when getting a contact", "url encodes the email when removing a contact", "url encodes the email when updating a contact", "url encodes the email in an audience-scoped path", "url encodes the email in topics paths", and "url encodes the email in segments paths".

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At spec/contacts_spec.rb, line 425:

<comment>Six newly added specs use `should` in their descriptions, which this repo's test-naming rule prohibits. Rename them declaratively, e.g. "url encodes the email when getting a contact", "url encodes the email when removing a contact", "url encodes the email when updating a contact", "url encodes the email in an audience-scoped path", "url encodes the email in topics paths", and "url encodes the email in segments paths".</comment>

<file context>
@@ -413,4 +413,49 @@
+      allow_any_instance_of(Resend::Request).to receive(:perform).and_return({})
+    end
+
+    it "should url encode the email when getting a contact" do
+      expect(Resend::Request).to receive(:new).with(encoded, {}, "get").and_call_original
+      Resend::Contacts.get(email: email)
</file context>

@LauraBeatris LauraBeatris self-assigned this Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant