Improve reIsUint to filter strings like '0001' and add tests.

This commit is contained in:
Xotic750
2015-10-30 22:27:51 +01:00
committed by John-David Dalton
parent 7e726735ba
commit c7ef030ef5
2 changed files with 4 additions and 1 deletions

View File

@@ -132,7 +132,7 @@
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to detect unsigned integer values. */
var reIsUint = /^\d+$/;
var reIsUint = /^(?:\d|[1-9]\d+)$/;
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;

View File

@@ -734,6 +734,7 @@
if (func) {
assert.strictEqual(func(0), true);
assert.strictEqual(func('0'), true);
assert.strictEqual(func('1'), true);
assert.strictEqual(func(3, 4), true);
assert.strictEqual(func(MAX_SAFE_INTEGER - 1), true);
@@ -748,6 +749,8 @@
if (func) {
assert.strictEqual(func('1abc'), false);
assert.strictEqual(func('07'), false);
assert.strictEqual(func('0001'), false);
assert.strictEqual(func(-1), false);
assert.strictEqual(func(3, 3), false);
assert.strictEqual(func(1.1), false);