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

Treat semicolons as a delimiter outside of groups. #5

Merged
merged 1 commit into from
Jan 7, 2015
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
10 changes: 9 additions & 1 deletion src/addressparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@
"(": ")",
"<": ">",
",": "",
":": ";"
// Groups are ended by semicolons
":": ";",
// Semicolons are not a legal delimiter per the RFC2822 grammar other
// than for terminating a group, but they are also not valid for any
// other use in this context. Given that some mail clients have
// historically allowed the semicolon as a delimiter equivalent to the
// comma in their UI, it makes sense to treat them the same as a comma
// when used outside of a group.
";": ""
};

/**
Expand Down
45 changes: 45 additions & 0 deletions test/addressparser-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("should handle quoted semicolons correctly", function() {
var input = "\"reinman; andris\" <andris@tr.ee>",
expected = [{
name: "reinman; andris",
address: "andris@tr.ee"
}];
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("should handle unquoted name, unquoted address correctly", function() {
var input = "andris andris@tr.ee",
expected = [{
Expand Down Expand Up @@ -86,6 +95,18 @@
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("should handle semicolon as a delimiter", function() {
var input = "andris@tr.ee; andris@example.com;",
expected = [{
address: "andris@tr.ee",
name: ""
}, {
address: "andris@example.com",
name: ""
}];
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("should handle mixed group correctly", function() {
var input = "Test User <test.user@mail.ee>, Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:;",
expected = [{
Expand All @@ -107,6 +128,30 @@
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("semicolon as delimiter should not break group parsing ", function() {
var input = "Test User <test.user@mail.ee>; Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:; bob@example.com;",
expected = [{
"address": "test.user@mail.ee",
"name": "Test User"
}, {
"name": "Disclosed",
"group": [{
"address": "andris@tr.ee",
"name": ""
}, {
"address": "andris@example.com",
"name": ""
}]
}, {
"name": "Undisclosed",
"group": []
}, {
"address": "bob@example.com",
"name": ""
}];
expect(addressparser.parse(input)).to.deep.equal(expected);
});

it("should handle name from comment correctly", function() {
var input = "andris@tr.ee (andris)",
expected = [{
Expand Down