Skip to content

Commit

Permalink
fixing #17
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 5, 2019
1 parent 6aaa71d commit c2bdcbb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"env": {
"es6": false,
"node": true,
"jasmine": true
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
11 changes: 4 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,10 @@
if (this.protocol) {
s += encode(this.protocol, options).replace(/%3A/g, ':') + '://';
}
if (this.user) {
s += encode(this.user, options);
if (this.password) {
s += ':' + encode(this.password, options);
if (this.user || this.password) {
if (this.user) {
s += encode(this.user, options);
}
s += '@';
} else {
if (this.password) {
s += ':';
var h = options.passwordHash;
Expand All @@ -184,8 +181,8 @@
} else {
s += encode(this.password, options);
}
s += '@';
}
s += '@';
}
if (Array.isArray(this.hosts)) {
s += this.hosts.map(function (h) {
Expand Down
2 changes: 2 additions & 0 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ describe('toString', () => {
expect(a.toString()).toBe('');
});
it('must secure passwords', () => {
expect(parse('user:abc@').toString({passwordHash: true})).toBe('user:###@');
expect(parse(':abc@').toString({passwordHash: true})).toBe(':###@');
expect(parse('user:abc@').toString({passwordHash: '123'})).toBe('user:111@');
expect(parse(':abc@').toString({passwordHash: '123'})).toBe(':111@');
});
});
Expand Down

0 comments on commit c2bdcbb

Please sign in to comment.