Fix query parameters conversion

This commit is contained in:
sonic
2015-05-15 02:47:57 +02:00
parent a88f5f8ae7
commit 2cccdb93b4
2 changed files with 4 additions and 1 deletions

View File

@ -9,7 +9,9 @@ _.mixin(_inflections)
// '1' -> 1 // '1' -> 1
function toNative (value) { function toNative (value) {
if (typeof value === 'string') { if (typeof value === 'string') {
if (value === '' || value.trim() !== value || value[0] === '0') { if (value === ''
|| value.trim() !== value
|| (value.length > 1 && value[0] === '0')) {
return value return value
} else if (value === 'true' || value === 'false') { } else if (value === 'true' || value === 'false') {
return value === 'true' return value === 'true'

View File

@ -36,6 +36,7 @@ describe('utils', function () {
it('should convert string to native type', function () { it('should convert string to native type', function () {
// should convert // should convert
assert.strictEqual(utils.toNative('1'), 1) assert.strictEqual(utils.toNative('1'), 1)
assert.strictEqual(utils.toNative('0'), 0)
assert.strictEqual(utils.toNative('true'), true) assert.strictEqual(utils.toNative('true'), true)
// should not convert // should not convert
assert.strictEqual(utils.toNative(''), '') assert.strictEqual(utils.toNative(''), '')