diff --git a/src/URI.js b/src/URI.js index 03f2c6c1..90514f70 100644 --- a/src/URI.js +++ b/src/URI.js @@ -77,6 +77,10 @@ return this; } + function isInteger(value) { + return /^[0-9]+$/.test(value); + } + URI.version = '1.18.11'; var p = URI.prototype; @@ -1058,7 +1062,7 @@ } var port = Number(v); - if (Number.isInteger(port) && (port > 0) && (port < 65536)) { + if (isInteger(port) && (port > 0) && (port < 65536)) { return; } diff --git a/test/test.js b/test/test.js index 8ebf8623..650241d4 100644 --- a/test/test.js +++ b/test/test.js @@ -1681,6 +1681,37 @@ deepEqual(links, expected, 'urls extracted'); equal(result, source, 'source not modified'); }); + test('ensureValidPort', function() { + var result; + + console.dir(URI); + result = URI.ensureValidPort(8080); + equal(result, true); + + result = URI.ensureValidPort("8080"); + equal(result, true); + + result = URI.ensureValidPort('a8080'); + equal(result, false); + + result = URI.ensureValidPort('8080a'); + equal(result, false); + + result = URI.ensureValidPort('0'); + equal(result, false); + + result = URI.ensureValidPort('-1'); + equal(result, false); + + result = URI.ensureValidPort(65535); + equal(result, true); + + result = URI.ensureValidPort(65536); + equal(result, false); + + result = URI.ensureValidPort(80.1); + equal(result, false); + }); test('noConflict', function() { var actual_lib = URI; // actual library; after loading, before noConflict() var unconflicted = URI.noConflict();