mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
fix: 修复 isJson 校验 (#2416)
Co-authored-by: wangfucheng <wangfucheng@machloop.com>
This commit is contained in:
parent
78c6ea4abb
commit
99f4b040ac
@ -465,6 +465,21 @@ test('validation:isJson invalid', () => {
|
||||
).toMatchObject(['请检查 Json 格式']);
|
||||
});
|
||||
|
||||
test('validation:isJson invalid', () => {
|
||||
expect(
|
||||
validate(
|
||||
'12345',
|
||||
{},
|
||||
{
|
||||
isJson: true
|
||||
},
|
||||
{
|
||||
isJson: '请检查 Json 格式'
|
||||
}
|
||||
)
|
||||
).toMatchObject(['请检查 Json 格式']);
|
||||
});
|
||||
|
||||
test('validation:isLength valid', () => {
|
||||
expect(
|
||||
validate(
|
||||
|
@ -149,7 +149,11 @@ export const validations: {
|
||||
isJson: function (values, value, minimum) {
|
||||
if (isExisty(value) && !isEmpty(value) && typeof value === 'string') {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
const result = JSON.parse(value);
|
||||
if (typeof result === 'object' && result) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user