Skip to content

Commit

Permalink
Replace all when handling + in emails (#258)
Browse files Browse the repository at this point in the history
* Replace all when handling + in emails

* update test
  • Loading branch information
tomrf1 authored Jan 13, 2025
1 parent f2b38a0 commit 00e57d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/create-reminder-signup/lambda/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ describe('request validation', () => {
it('transforms an email address containing a space', () => {
// Identity’s guest creation endpoint errors if the provided email address is more than 100 characters long
// See baseSignupRequestSchema definition for details
const email = 'test afterplus@theguardian.com';
const email = 'test after plus@theguardian.com';
const result = oneOffSignupRequestSchema.safeParse({
...oneOffSignupRequest,
email,
});
expect(result.success).toBe(true);
expect(result.data?.email).toBe('test+afterplus@theguardian.com');
expect(result.data?.email).toBe('test+after+plus@theguardian.com');
});
});
2 changes: 1 addition & 1 deletion src/create-reminder-signup/lambda/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const baseSignupRequestSchema = z.object({
// Identity’s guest creation endpoint errors if the provided email address is more than 100 characters long
.max(100)
// The API gateway -> SQS integration encodes + as a space in the email string
.transform((email) => email.replace(' ', '+'))
.transform((email) => email.replace(/ /g, '+'))
.pipe(z.string().email()),
country: z.string().optional(),
reminderCreatedAt: z.string().datetime().optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const idapiBaseUrl = isProd()
: 'https://idapi.code.dev-theguardian.com';

const encodeEmail = (email: string): string =>
encodeURI(email).replace('+', '%2B');
encodeURI(email).replace(/\+/g, '%2B');

export interface IdentitySuccess {
name: 'success';
Expand Down

0 comments on commit 00e57d8

Please sign in to comment.