Updated validate null check

This commit is contained in:
thomashii@dukefirehawk.com 2023-10-29 15:02:05 +08:00
parent 0ca3eb7e01
commit 834406de2d
3 changed files with 14 additions and 5 deletions

View file

@ -1,5 +1,9 @@
# Change Log
## 8.0.1
* Fixed null check throwing exception
## 8.0.0
* Require Dart >= 3.0

View file

@ -162,7 +162,8 @@ class Validator extends Matcher {
var value = input[key];
var description = StringDescription("'$key': expected ");
for (var matcher in rules[key]!) {
var rulesList = rules[key] ?? [];
for (var matcher in rulesList) {
if (matcher is ContextValidator) {
if (!matcher.validate(key, input)) {
errors.add(matcher
@ -175,7 +176,8 @@ class Validator extends Matcher {
}
if (valid) {
for (var matcher in rules[key]!) {
var rulesList = rules[key] ?? [];
for (var matcher in rulesList) {
try {
if (matcher is Validator) {
var result = matcher.check(value as Map);
@ -320,7 +322,10 @@ class Validator extends Matcher {
return;
}
rules[key]!.add(rule);
if (rules[key] == null) {
rules[key] = List.empty(growable: true);
}
rules[key]?.add(rule);
}
/// Adds all given [rules].
@ -333,7 +338,7 @@ class Validator extends Matcher {
/// Removes a [rule].
void removeRule(String key, Matcher rule) {
if (rules.containsKey(key)) {
rules[key]!.remove(rule);
rules[key]?.remove(rule);
}
}

View file

@ -1,6 +1,6 @@
name: angel3_validate
description: Cross-platform HTTP request body validator library based on `matcher`.
version: 8.0.0
version: 8.0.1
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/validate
environment: