Skip to content
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
3 changes: 0 additions & 3 deletions src/imap-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@

// space finishes an atom
if (chr === " ") {
if ([")", "]"].indexOf(this.str.charAt(i + 1)) >= 0) {
throw new Error("Unexpected whitespace at position " + (this.pos + i + 1));
}
this.currentNode.endPos = this.pos + i - 1;
this.currentNode = this.currentNode.parentNode;
this.state = "NORMAL";
Expand Down
51 changes: 45 additions & 6 deletions test/imap-parser-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,21 @@
value: "1234"
}]
]);
// Trailing whitespace in a BODYSTRUCTURE atom list has been
// observed on yahoo.co.jp's
expect(imapHandler.parser("TAG1 CMD (1234 )").attributes).to.deep.equal([
[{
type: "ATOM",
value: "1234"
}]
]);
expect(imapHandler.parser("TAG1 CMD (1234) ").attributes).to.deep.equal([
[{
type: "ATOM",
value: "1234"
}]
]);
});
it("should fail", function() {
expect(function() {
imapHandler.parser("TAG1 CMD (1234 )");
}).to.throw(Error);
});

});

describe('nested list', function() {
Expand Down Expand Up @@ -254,6 +256,19 @@
}
]
]);
expect(imapHandler.parser("TAG1 CMD (((TERE) ) VANA)").attributes).to.deep.equal([
[
[
[{
type: "ATOM",
value: "TERE"
}]
], {
type: "ATOM",
value: "VANA"
}
]
]);
});
});

Expand Down Expand Up @@ -318,6 +333,30 @@
]
}]);
});
it("will not fail due to trailing whitespace", function() {
// We intentionally have trailing whitespace in the section here
// because we altered the parser to handle this when we made it
// legal for lists and it makes sense to accordingly test it.
// However, we have no recorded incidences of this happening in
// reality (unlike for lists).
expect(imapHandler.parser("TAG1 CMD BODY[HEADER.FIELDS (Subject From) ]").attributes).to.deep.equal([{
type: "ATOM",
value: "BODY",
section: [
{
type: 'ATOM',
value: 'HEADER.FIELDS'
},
[{
type: "ATOM",
value: "Subject"
}, {
type: "ATOM",
value: "From"
}]
]
}]);
});
it("should fail where default BODY and BODY.PEEK are allowed to have sections", function() {});
expect(function() {
imapHandler.parser("TAG1 CMD KODY[]");
Expand Down