提交 2b4ff012 编写于 作者: 雪洛's avatar 雪洛

fix: validator error

上级 984f7396
......@@ -290,6 +290,12 @@ function createPasswordVerifier({
}
}
function isEmpty(value) {
return value === undefined ||
value === null ||
(typeof value === 'string' && value.trim() === '')
}
class Validator {
constructor({
passwordStrength = ''
......@@ -350,7 +356,7 @@ class Validator {
type
} = schemaValue
// value内未传入了schemaKey或对应值为undefined
if (value[schemaKey] === undefined) {
if (isEmpty(value[schemaKey])) {
if (required) {
return {
errCode: ERROR.PARAM_REQUIRED,
......@@ -360,6 +366,7 @@ class Validator {
schemaKey
}
} else {
delete value[schemaKey]
continue
}
}
......
......@@ -151,6 +151,46 @@ const testCaseList = [{
schema: {
numberOrString: 'array<number|1to6>'
}
}, {
value: {
username: ''
},
schema: {
username: {
required: false,
type: 'username'
}
}
}, {
value: {
username: ' '
},
schema: {
username: {
required: false,
type: 'username'
}
}
}, {
value: {
username: ' '
},
schema: {
username: 'username'
},
expected: {
errCode: ERROR.PARAM_REQUIRED
}
}, {
value: {
username: ''
},
schema: {
username: 'username'
},
expected: {
errCode: ERROR.PARAM_REQUIRED
}
}]
function execTestCase ({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册