Skip to content

Commit 02ca175

Browse files
committed
Fix U.parseInt().
1 parent 958c5d9 commit 02ca175

2 files changed

Lines changed: 6 additions & 27 deletions

File tree

test/test-utils.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ function prototypeString() {
165165
str = ' a ';
166166
assert.ok(str.parseInt() === 0, 'string.parseInt(): ' + str);
167167

168+
str = ' a ';
169+
assert.ok(str.parseInt(-1) === -1, 'string.parseInt(): ' + str + ' / default');
170+
168171
str = '';
169172
assert.ok(str.parseInt() === 0, 'string.parseInt(): ' + str);
170173

@@ -447,15 +450,6 @@ function other() {
447450
str = '.xFx';
448451
assert.ok(utils.getContentType(str) === 'application/octet-stream', 'utils.getContentType(): ' + str);
449452

450-
str = 'logo.jpg';
451-
assert.ok(utils.etag(str) === '800', 'utils.etag(): ' + str);
452-
453-
str = 'logo.jpg?=1';
454-
assert.ok(utils.etag(str) === '973', 'utils.etag(): ' + str);
455-
456-
str = 'logo.jpg?=2';
457-
assert.ok(utils.etag(str) === '974', 'utils.etag(): ' + str);
458-
459453
str = '/logo';
460454
assert.ok(utils.path(str) === '/logo/', 'utils.path(): ' + str);
461455

utils.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,23 +1507,14 @@ exports.parseInt = function(obj, def) {
15071507
if (obj == null)
15081508
return def || 0;
15091509
var type = typeof(obj);
1510-
return type === 'number' ? obj : (type !== 'string' ? obj.toString() : obj).parseInt();
1510+
return type === 'number' ? obj : (type !== 'string' ? obj.toString() : obj).parseInt(def);
15111511
};
15121512

15131513
exports.parseBool = exports.parseBoolean = function(obj, def) {
1514-
15151514
if (obj == null)
15161515
return def === undefined ? false : def;
1517-
15181516
var type = typeof(obj);
1519-
if (type === 'boolean')
1520-
return obj;
1521-
1522-
if (type === 'number')
1523-
return obj > 0;
1524-
1525-
var str = type !== 'string' ? obj.toString() : obj;
1526-
return str.parseBool(def);
1517+
return type === 'boolean' ? obj : type === 'number' ? obj > 0 : (type !== 'string' ? obj.toString() : obj).parseBool(def);
15271518
};
15281519

15291520
/**
@@ -1533,16 +1524,10 @@ exports.parseBool = exports.parseBoolean = function(obj, def) {
15331524
* @return {Number}
15341525
*/
15351526
exports.parseFloat = function(obj, def) {
1536-
15371527
if (obj == null)
15381528
return def || 0;
1539-
15401529
var type = typeof(obj);
1541-
if (type === 'number')
1542-
return obj;
1543-
1544-
var str = type !== 'string' ? obj.toString() : obj;
1545-
return str.parseFloat(def);
1530+
return type === 'number' ? obj : (type !== 'string' ? obj.toString() : obj).parseFloat(def);
15461531
};
15471532

15481533
/**

0 commit comments

Comments
 (0)