Skip to content

Commit

Permalink
Merge pull request #293 from mika-fischer/master
Browse files Browse the repository at this point in the history
fix(authority): support empty username with non-empty password
  • Loading branch information
rodneyrehm committed Apr 26, 2016
2 parents 6515820 + 8ae9c94 commit ed2e035
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,13 @@

if (parts.username) {
t += URI.encode(parts.username);
}

if (parts.password) {
t += ':' + URI.encode(parts.password);
}
if (parts.password) {
t += ':' + URI.encode(parts.password);
}

if (t) {
t += '@';
}

Expand Down Expand Up @@ -1334,12 +1336,8 @@
}

if (v === undefined) {
if (!this._parts.username) {
return '';
}

var t = URI.buildUserinfo(this._parts);
return t.substring(0, t.length -1);
return t ? t.substring(0, t.length -1) : t;
} else {
if (v[v.length-1] !== '@') {
v += '@';
Expand Down
49 changes: 49 additions & 0 deletions test/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,55 @@ var urls = [{
idn: false,
punycode: false
}
}, {
name: 'empty username with non-empty password',
url: 'scheme://:password@www.example.org/',
_url: 'scheme://:password@www.example.org/',
parts: {
protocol: 'scheme',
username: null,
password: 'password',
hostname: 'www.example.org',
port: null,
path: '/',
query: null,
fragment: null
},
accessors: {
protocol: 'scheme',
username: '',
password: 'password',
port: '',
path: '/',
query: '',
fragment: '',
resource: '/',
authority: ':password@www.example.org',
origin: 'scheme://:password@www.example.org',
userinfo: ':password',
subdomain: 'www',
domain: 'example.org',
tld: 'org',
directory: '/',
filename: '',
suffix: '',
hash: '',
search: '',
host: 'www.example.org',
hostname: 'www.example.org'
},
is: {
urn: false,
url: true,
relative: false,
name: true,
sld: false,
ip: false,
ip4: false,
ip6: false,
idn: false,
punycode: false
}
}, {
name: 'malformed email in userinfo',
url: 'scheme://john@doe.com:pass:word@www.example.org/',
Expand Down

0 comments on commit ed2e035

Please sign in to comment.