From ea63e0db710156153a49f5dea237f4255fa48d1e Mon Sep 17 00:00:00 2001 From: Aaron Ballard Date: Sat, 5 May 2018 21:17:23 -0500 Subject: [PATCH] add support for @ signs in usernames. Doesn't seem to break anything to just throw it on the end of the username portion of the regex --- lib/client.js | 2 +- test/client.test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index f73981d..2a6f4fe 100644 --- a/lib/client.js +++ b/lib/client.js @@ -25,7 +25,7 @@ Client.prototype.defaults = function(options) { Client.prototype.parse = function(remote) { if (_.isString(remote)) { // username[:password]@host[:port][:/path/to] - var regex = /^([a-zA-Z0-9\-\._]+)(?:\:(.*))?@([^:]+)(?:\:([0-9]+))?(?:\:(.*))?$/; + var regex = /^([a-zA-Z0-9\-\._@]+)(?:\:(.*))?@([^:]+)(?:\:([0-9]+))?(?:\:(.*))?$/; var m = remote.match(regex); if (!m) return {}; var ret = { diff --git a/test/client.test.js b/test/client.test.js index 1230d70..2ada0de 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -121,6 +121,15 @@ describe('Client', function() { expect(ret.path).to.equal('/home/admin/path'); }); + it('can handle "@" in username', function() { + ret = client.parse('admin@2:bx%9@example.com:12345:/home/admin/path'); + expect(ret.username).to.equal('admin@2'); + expect(ret.password).to.equal('bx%9'); + expect(ret.host).to.equal('example.com'); + expect(ret.port).to.equal('12345'); + expect(ret.path).to.equal('/home/admin/path'); + }); + }); describe('when calling from windows', function() {