Skip to content

Commit

Permalink
Removed a couple checks that could never occur.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTPate committed Aug 5, 2014
1 parent d4455c9 commit c321746
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
34 changes: 12 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function decompose(url, str) {
} else if (charCode === octothorpe) {
// Hash value
url.hash = str.substring(1, str.length);
} else if(matches = giantPattern.exec(str)) {
} else if (matches = giantPattern.exec(str)) {
// Full URL
return decomposeUrl(url, matches);
} else {
Expand All @@ -80,30 +80,24 @@ function decomposeUrl(url, str) {
matches = giantPattern.exec(str);
}

if (matches) {
url.protocol = matches[2] || null;
url.username = matches[4] || null;
url.password = matches[5] || null;
url.hostname = matches[6] || null;
url.host = url.hostname ? url.hostname.split('.') : null;
url.protocol = matches[2] || null;
url.username = matches[4] || null;
url.password = matches[5] || null;
url.hostname = matches[6] || null;
url.host = url.hostname ? url.hostname.split('.') : null;

if (url.host && url.host.length > 1) {
var tld = url.host && url.host.slice(url.host.length - 1)[0];
url.tld = !isNumberic(tld) && tld;
}
if (url.host && url.host.length > 1) {
var tld = url.host && url.host.slice(url.host.length - 1)[0];
url.tld = !isNumberic(tld) && tld;
}

url.port = matches[8] || '80';
url.port = matches[8] || '80';

url = decompose(url, matches[9]);
}
url = decompose(url, matches[9]);
return url;
}

function decomposePath(url, str) {
if (!str) {
return url;
}

var simplePath = simplePathRegExp.exec(str);

if (simplePath) {
Expand All @@ -126,10 +120,6 @@ function decomposePath(url, str) {
}

function parseQueryString(str) {
if (!str || typeof str !== 'string') {
return null;
}

var obj = {};

var matches = queryStringPattern.exec(str),
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('decompose-url(url)', function () {
parsed.hash.should.be.exactly('david-rules');
parsed.href.should.be.exactly('//username:password@test.example.com/one/two/three?value=abc&value2=123#david-rules');
});
it.only('should parse a protocol relative URL pointing to the root', function () {
it('should parse a protocol relative URL pointing to the root', function () {
var parsed = decomposeUrl('//');

(!!!parsed.protocol).should.be.true;
Expand Down

0 comments on commit c321746

Please sign in to comment.