diff --git a/lib/command-parser.js b/lib/command-parser.js index 4d338ce..7bebc52 100644 --- a/lib/command-parser.js +++ b/lib/command-parser.js @@ -11,7 +11,11 @@ function splitToken(msg) { return; } - return msg.trim().split(/[\s\.]+/); // eslint-disable-line no-useless-escape + const delimiters = msg.trim().match(/^\w+(\W)/); + const delimiter = delimiters && delimiters[1] ? delimiters[1] : null; + + const delimiterRegex = delimiter ? new RegExp('\\' + delimiter + '+') : new RegExp('[\\s\\.]+'); + return msg.trim().split(delimiterRegex); } function _makeSureAsTokensArray(msgOrTokens) { diff --git a/test/command-parser.js b/test/command-parser.js index bfe5aa6..41d4b89 100644 --- a/test/command-parser.js +++ b/test/command-parser.js @@ -13,6 +13,10 @@ describe('#command-parser', function() { commandParser.splitToken('SAL.1234')[1].should.equal('1234'); commandParser.splitToken('SAL 1234')[1].should.equal('1234'); + + }) + + it('should handle repeating splitter', function() { commandParser.splitToken('SAL 1234')[1].should.equal('1234'); })