Skip to content

Commit

Permalink
fix(ensureValidPort) Use local version of isInteger, remove Number.is…
Browse files Browse the repository at this point in the history
…Integer. Add tests - medialize#350
  • Loading branch information
jeff-phillips-18 committed Aug 10, 2017
1 parent 8043e13 commit 744516f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
return this;
}

function isInteger(value) {
return /^[0-9]+$/.test(value);
}

URI.version = '1.18.11';

var p = URI.prototype;
Expand Down Expand Up @@ -1058,7 +1062,7 @@
}

var port = Number(v);
if (Number.isInteger(port) && (port > 0) && (port < 65536)) {
if (isInteger(port) && (port > 0) && (port < 65536)) {
return;
}

Expand Down
30 changes: 30 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,36 @@
deepEqual(links, expected, 'urls extracted');
equal(result, source, 'source not modified');
});
test('ensureValidPort', function() {

function testPort(value) {
var result = true;
try {
URI.ensureValidPort(value);
} catch(e) {
result = false;
}

return result;
}

equal(testPort(8000), true);
equal(testPort('8080'), true);

equal(testPort(0), true);
equal(testPort(1), true);

equal(testPort(65535), true);
equal(testPort(65536), false);

equal(testPort(-8080), false);
equal(testPort('-8080'), false);

equal(testPort('aaa8080'), false);
equal(testPort('8080a'), false);

equal(testPort(8080.2), false);
});
test('noConflict', function() {
var actual_lib = URI; // actual library; after loading, before noConflict()
var unconflicted = URI.noConflict();
Expand Down

0 comments on commit 744516f

Please sign in to comment.