From 2405fedbd998d3402d337f14d7f9ed1a3f919c30 Mon Sep 17 00:00:00 2001 From: Andrew Sutherland Date: Tue, 23 Sep 2014 08:33:23 -0400 Subject: [PATCH] Handle NIL delimiters --- src/browserbox.js | 2 +- test/unit/browserbox-test.js | 44 +++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/browserbox.js b/src/browserbox.js index 0e1a6038..666521fd 100644 --- a/src/browserbox.js +++ b/src/browserbox.js @@ -645,7 +645,7 @@ if (!item || !item.attributes || item.attributes.length < 3) { return; } - var branch = this._ensurePath(tree, (item.attributes[2].value || '').toString(), (item.attributes[1].value).toString()); + var branch = this._ensurePath(tree, (item.attributes[2].value || '').toString(), (item.attributes[1] ? item.attributes[1].value : '/').toString()); branch.flags = [].concat(item.attributes[0] || []).map(function(flag) { return (flag.value || '').toString(); }); diff --git a/test/unit/browserbox-test.js b/test/unit/browserbox-test.js index 3b258373..e32db64d 100644 --- a/test/unit/browserbox-test.js +++ b/test/unit/browserbox-test.js @@ -2,11 +2,11 @@ (function(factory) { if (typeof define === 'function' && define.amd) { - define(['chai', 'sinon', 'axe', 'browserbox', './fixtures/mime-torture-bodystructure', './fixtures/envelope'], factory); + define(['chai', 'sinon', 'axe', 'browserbox', 'imap-handler', './fixtures/mime-torture-bodystructure', './fixtures/envelope'], factory); } else if (typeof exports === 'object') { - module.exports = factory(require('chai'), require('sinon'), require('axe-logger'), require('browserbox'), require('./fixtures/mime-torture-bodystructure'), require('./fixtures/envelope')); + module.exports = factory(require('chai'), require('sinon'), require('axe-logger'), require('browserbox'), require('imap-handler'), require('./fixtures/mime-torture-bodystructure'), require('./fixtures/envelope')); } -}(function(chai, sinon, axe, BrowserBox, mimeTorture, testEnvelope) { +}(function(chai, sinon, axe, BrowserBox, imapHandler, mimeTorture, testEnvelope) { var expect = chai.expect; chai.Assertion.includeStack = true; @@ -505,6 +505,44 @@ expect(tree).to.exist; }); }); + + it('should not die on NIL separators', function(done) { + sinon.stub(br, 'exec', function(command, untagged, callback) { + br.exec.restore(); + sinon.stub(br, 'exec', function(command, untagged, callback) { + br.exec.restore(); + + expect(command).to.deep.equal({ + command: 'LSUB', + attributes: ['', '*'] + }); + callback(null, { + payload: { + LSUB: [false] + } + }, function() { + done(); + }); + }); + + expect(command).to.deep.equal({ + command: 'LIST', + attributes: ['', '*'] + }); + callback(null, { + payload: { + LIST: [ + imapHandler.parser('* LIST (\\NoInferiors) NIL "INBOX"') + ] + } + }, function() {}); + }); + + br.listMailboxes(function(err, tree) { + expect(err).to.not.exist; + expect(tree).to.exist; + }); + }); }); describe('#listMessages', function() {