Skip to content

Commit e660f0b

Browse files
committed
Fix empty string conversion
1 parent 357b707 commit e660f0b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ _.mixin(_inflections)
88
// '1' -> 1
99
function toNative(value) {
1010
if (typeof value === 'string') {
11-
if (value === 'true' || value === 'false') {
11+
if (value === '') {
12+
return value
13+
} else if (value === 'true' || value === 'false') {
1214
return value === 'true'
1315
} else if (!isNaN(+value)) {
1416
return +value

test/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ describe('utils', function() {
3232
describe('toNative', function() {
3333

3434
it('should convert string to native type', function() {
35-
35+
// should convert
3636
assert.strictEqual(utils.toNative('1'), 1)
3737
assert.strictEqual(utils.toNative('true'), true)
38-
38+
// should not convert
39+
assert.strictEqual(utils.toNative(''), '')
3940
assert.strictEqual(utils.toNative('string'), 'string')
4041
assert.strictEqual(utils.toNative(1), 1)
4142
assert.strictEqual(utils.toNative(true), true)
42-
4343
})
4444

4545
})

0 commit comments

Comments
 (0)