Skip to content

Commit

Permalink
fix(ensureValidPort): replace Number.isInteger() with local util (#350,
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 authored and rodneyrehm committed Aug 10, 2017
1 parent fdb47bf commit 0d20f98
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
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
Expand Up @@ -1700,6 +1700,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 0d20f98

Please sign in to comment.