diff --git a/packages/validate/CHANGELOG.md b/packages/validate/CHANGELOG.md index b7f3d420..b4d8b308 100644 --- a/packages/validate/CHANGELOG.md +++ b/packages/validate/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 8.0.1 + +* Fixed null check throwing exception + ## 8.0.0 * Require Dart >= 3.0 diff --git a/packages/validate/lib/src/validator.dart b/packages/validate/lib/src/validator.dart index e52ff0da..c7092e7f 100644 --- a/packages/validate/lib/src/validator.dart +++ b/packages/validate/lib/src/validator.dart @@ -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); } } diff --git a/packages/validate/pubspec.yaml b/packages/validate/pubspec.yaml index 06b946e6..22096d19 100644 --- a/packages/validate/pubspec.yaml +++ b/packages/validate/pubspec.yaml @@ -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: