Skip to content

Commit 3dcd609

Browse files
committed
shallow copy
1 parent 3bc3ad8 commit 3dcd609

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

packages/mail/src/classes/mail-service.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class MailService {
181181
try {
182182

183183
// copy object to avoid mutating original
184-
const args = data;
184+
const args = { ...data };
185185
//Append multiple flag to data if not set
186186
if (typeof data.isMultiple === 'undefined') {
187187
args.isMultiple = isMultiple;
@@ -191,11 +191,10 @@ class MailService {
191191
if (typeof data.substitutionWrappers === 'undefined') {
192192
args.substitutionWrappers = this.substitutionWrappers;
193193
}
194-
195194
//Create Mail instance from data and get JSON body for request
196195
const mail = Mail.create(args);
197196
const body = mail.toJSON();
198-
197+
199198
//Filters the Mail body to avoid sensitive content leakage
200199
this.filterSecrets(body);
201200

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { assert } = require('chai');
2+
3+
const MailService = require('./mail-service');
4+
describe('MailService send', () => {
5+
it('should not mutate original data variable', () => {
6+
const mailService = new MailService();
7+
mailService.setClient({
8+
request: (req, cb) => {
9+
return new Promise((resolve) => {
10+
resolve();
11+
});
12+
},
13+
});
14+
const data = {
15+
16+
from: '[email protected]', // Use the email address or domain you verified above
17+
subject: 'Sending with Twilio SendGrid is Fun',
18+
text: 'and easy to do anywhere, even with Node.js',
19+
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
20+
};
21+
return mailService.send(data).then(() => {
22+
assert.deepStrictEqual(data,
23+
{
24+
25+
from: '[email protected]', // Use the email address or domain you verified above
26+
subject: 'Sending with Twilio SendGrid is Fun',
27+
text: 'and easy to do anywhere, even with Node.js',
28+
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
29+
});
30+
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)