Skip to content

Commit

Permalink
fix(Number.isInteger) Add polyfill for Number.isInteger - medialize#350
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Aug 10, 2017
1 parent 8043e13 commit 54732ff
Show file tree
Hide file tree
Showing 2 changed files with 36 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
31 changes: 31 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 54732ff

Please sign in to comment.