From c2a859727de65dd5ff48b64e9c5c7c2f187b06cf Mon Sep 17 00:00:00 2001 From: Suraj Sharma Date: Mon, 14 Mar 2016 15:55:55 +0530 Subject: [PATCH] Parser: handle tagged responses without response code and/or other text --- lib/Parser.js | 2 +- test/test-parser.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Parser.js b/lib/Parser.js index 1a95870..c00a1ac 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -18,7 +18,7 @@ var CH_LF = 10, RE_LISTCONTENT = /^\((.*)\)$/, RE_LITERAL = /\{(\d+)\}$/, RE_UNTAGGED = /^\* (?:(OK|NO|BAD|BYE|FLAGS|ID|LIST|XLIST|LSUB|SEARCH|STATUS|CAPABILITY|NAMESPACE|PREAUTH|SORT|THREAD|ESEARCH|QUOTA|QUOTAROOT)|(\d+) (EXPUNGE|FETCH|RECENT|EXISTS))(?:(?: \[([^\]]+)\])?(?: (.+))?)?$/i, - RE_TAGGED = /^A(\d+) (OK|NO|BAD) (?:\[([^\]]+)\] )?(.+)$/i, + RE_TAGGED = /^A(\d+) (OK|NO|BAD) ?(?:\[([^\]]+)\] )?(.*)$/i, RE_CONTINUE = /^\+(?: (?:\[([^\]]+)\] )?(.+))?$/i, RE_CRLF = /\r\n/g, RE_HDR = /^([^:]+):[ \t]?(.+)?$/, diff --git a/test/test-parser.js b/test/test-parser.js index d99e375..f438571 100644 --- a/test/test-parser.js +++ b/test/test-parser.js @@ -465,6 +465,15 @@ var CR = '\r', LF = '\n', CRLF = CR + LF; ], what: 'QuotaRoot' }, + { source: ['A1 OK', CRLF], // some servers like ppops.net sends such response + expected: [ { type: 'ok', + tagnum: 1, + textCode: undefined, + text: '' + } + ], + what: 'Tagged OK (no text code, no text)' + }, ].forEach(function(v) { var ss = new require('stream').Readable(), p, result = []; ss._read = function(){};