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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The function returns an object in the following form:
Where

- **tag** is a string containing the tag
- **command** is the first element after tag
- **command** is the first element after tag. It is an atom (RFC 3501 section 9, `x-command = "X" atom`), so besides letters and digits it can hold chars like `-`, `.`, `/` or `=`. Do not use it to build file paths without checking it first
- **attributes** (if present) is an array of next elements

If section or partial values are not specified in the command, the values are also missing from the ATOM element
Expand Down
4 changes: 3 additions & 1 deletion lib/formal.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ module.exports = {
return this._excludeChars(this['ASTRING-CHAR'](), '+');
},

// RFC 3501 9: command names are atoms, e.g. x-command = "X" atom, and the second word of
// UID and AUTHENTICATE is an atom too (auth-type = atom)
command: function () {
const value = this.ALPHA() + this.DIGIT();
const value = this['ATOM-CHAR']();
this.command = function () {
return value;
};
Expand Down
15 changes: 12 additions & 3 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ describe('COMMAND', () => {
});

it('Get command fail (invalid char)', () => {
assert.throws(() => {
parser('TAG1 CM=D');
});
// RFC 3501 9: atom-specials and 8-bit octets are not ATOM-CHARs
for (const command of ['CM(D', 'CM"D', 'CM%D', 'CM*D', 'CM]D', 'CM{D', 'CM\\D', 'CM\x7fD', 'CM\xe9D']) {
assert.throws(() => parser('TAG1 ' + command), /Unexpected char/, command);
}
});

// RFC 3501 9: x-command = "X" atom, auth-type = atom
it('Get command with atom chars', () => {
assert.equal(parser('TAG1 X-FOO.BAR').command, 'X-FOO.BAR');
assert.equal(parser('TAG1 CM=D').command, 'CM=D');
assert.equal(parser('TAG1 AUTHENTICATE PLAIN-CLIENTTOKEN').command, 'AUTHENTICATE PLAIN-CLIENTTOKEN');
assert.equal(parser('TAG1 AUTHENTICATE SCRAM-SHA-256 =').command, 'AUTHENTICATE SCRAM-SHA-256');
});
it('Get multi word command', () => {
assert.equal(parser('TAG1 UID FETCH').command, 'UID FETCH');
Expand Down