Skip to content

Commit ad8db59

Browse files
committed
on 2nd thought, only coerce numbers to strings
1 parent a2c52fe commit ad8db59

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/lib/coerce.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ exports.valObjects = {
100100
otherOpts: ['dflt', 'noBlank', 'strict', 'arrayOk', 'values'],
101101
coerceFunction: function(v, propOut, dflt, opts) {
102102
if(typeof v !== 'string') {
103-
var okToCoerce = (
104-
typeof v === 'number' ||
105-
v instanceof Date ||
106-
typeof v === 'boolean'
107-
);
103+
var okToCoerce = (typeof v === 'number');
108104

109105
if(opts.strict === true || !okToCoerce) propOut.set(dflt);
110106
else propOut.set(String(v));

test/jasmine/tests/lib_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('Test lib.js:', function() {
529529
.toEqual(dflt);
530530

531531
expect(coerce({s: true}, {}, stringAttrs, 's'))
532-
.toEqual('true');
532+
.toEqual(dflt);
533533

534534
expect(coerce({s: {1: 2}}, {}, stringAttrs, 's'))
535535
.toEqual(dflt);
@@ -878,12 +878,12 @@ describe('Test lib.js:', function() {
878878
it('should work for valType \'string\' where', function() {
879879
var date = new Date(2016, 1, 1);
880880

881-
assert(['3', '4', 'a', 3, 1.2113, '', date, false], [undefined, {}, [], null], {
881+
assert(['3', '4', 'a', 3, 1.2113, ''], [undefined, {}, [], null, date, false], {
882882
valType: 'string',
883883
dflt: 'a'
884884
});
885885

886-
assert(['3', '4', 'a', 3, 1.2113, date, true], ['', undefined, {}, [], null], {
886+
assert(['3', '4', 'a', 3, 1.2113], ['', undefined, {}, [], null, date, true], {
887887
valType: 'string',
888888
dflt: 'a',
889889
noBlank: true

0 commit comments

Comments
 (0)