Repository navigation
fix(contacts): encode the contact id or email in the request path - #277
Draft
LauraBeatris wants to merge 1 commit into
Draft
LauraBeatris wants to merge 1 commit into
LauraBeatris wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 4/5
spec/contacts_spec.rbhas six new spec descriptions usingshould, 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
| allow_any_instance_of(Resend::Request).to receive(:perform).and_return({}) | ||
| end | ||
|
|
||
| it "should url encode the email when getting a contact" do |
Contributor
There was a problem hiding this comment.
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>
This branch has not been deployed
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.
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.
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.comanda=b@example.com. Lookups by email need to work for them.Fix
The contact id or email now goes through
ERB::Util.url_encodebefore 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.comwould be truncated at the#, sending the request to/contacts/aand 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 (%40for@) the same as the raw value.Contacts.get,update, andremove(with and withoutaudience_id),Topics.listandupdate, andSegments.list,add, andremove.a#b@example.com.Same fix as resend/resend-node#1217.
Written for commit d7a3d78. Summary will update on new commits.