Skip to content

Commit

Permalink
Merge pull request #5 from asutherland/semicolons-as-delim
Browse files Browse the repository at this point in the history
Treat semicolons as a delimiter outside of groups.
  • Loading branch information
andris9 committed Jan 7, 2015
2 parents f5bfce9 + 356068e commit e5c9c0c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
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

0 comments on commit e5c9c0c

Please sign in to comment.