Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma bug in name #448 #522

Merged
merged 3 commits into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/helpers/classes/email-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class EmailAddress {
if (typeof name !== 'string') {
throw new Error('String expected for `name`');
}
this.name = name;
// Wrap name in quotes to address API issue
// https://github.com/sendgrid/sendgrid-csharp/issues/268#issuecomment-232177443
const isQuoted = (name[0] === '\"') && (name[name.length - 1] === '\"');
const shouldQuote = name.includes(',') && !isQuoted;
this.name = shouldQuote ? `\"${name}\"` : name;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/helpers/classes/email-address.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('EmailAddress', function() {
email.setName('Test');
expect(email.name).to.equal('Test');
});

it('should wrap name in quotes if a comma is present', function() {
email.setName('Doe, John');
expect(email.name).to.equal('\"Doe, John\"');
});

it('should not double wrap in quotes', function() {
email.setName('\"Doe, John\"');
expect(email.name).to.equal('\"Doe, John\"');
});
it('should throw an error for invalid input', function() {
expect(function() {
email.setName(5);
Expand Down