mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Throw warning on missing client validation
Client-side validation is not essential (we can only rely on server-side validation being enforced). So it doesn’t make sense to throw an exception in this context, and stop the entire CMS execution because of missing rules.
This commit is contained in:
parent
558a171366
commit
fa2ef05ef1
3
admin/client/dist/js/bundle.js
vendored
3
admin/client/dist/js/bundle.js
vendored
@ -424,7 +424,8 @@ case"alphanumeric":return u["default"].isAlphanumeric(e)
|
||||
case"alpha":return u["default"].isAlpha(e)
|
||||
case"regex":return u["default"].matches(e,n.pattern)
|
||||
case"max":return e.length<=n.length
|
||||
default:throw new Error("Unknown validation rule used: '"+t+"'")}}},{key:"validateFieldSchema",value:function l(e){return this.validateField(e.name,e.validation,null!==e.leftTitle?e.leftTitle:e.title,e.customValidationMessage)
|
||||
case"email":return u["default"].isEmail(e)
|
||||
default:console.warn("Unknown validation rule used: '"+t+"'")}}},{key:"validateFieldSchema",value:function l(e){return this.validateField(e.name,e.validation,null!==e.leftTitle?e.leftTitle:e.title,e.customValidationMessage)
|
||||
|
||||
}},{key:"getMessage",value:function d(e,t){var n=""
|
||||
if("string"==typeof t.message)n=t.message
|
||||
|
@ -60,7 +60,9 @@ class Validator {
|
||||
return validator.isEmail(value);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown validation rule used: '${rule}'`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`Unknown validation rule used: '${rule}'`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
/* global jest, describe, beforeEach, it, expect */
|
||||
/* global jest, describe, beforeEach, it, expect, console */
|
||||
|
||||
// Needs to be set before requiring other libraries
|
||||
global.console = { warn: jest.fn() };
|
||||
|
||||
jest.unmock('react');
|
||||
jest.unmock('react-addons-test-utils');
|
||||
@ -56,9 +59,9 @@ describe('Validator', () => {
|
||||
describe('validateValue()', () => {
|
||||
it('should throw an error', () => {
|
||||
validator = new Validator({});
|
||||
const callRuleDoesNotExist = () => validator.validateValue('one', 'ruledoesnotexist');
|
||||
|
||||
expect(callRuleDoesNotExist).toThrowError(/unknown/i);
|
||||
validator.validateValue('one', 'ruledoesnotexist');
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.warn).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user