From f2a2ed6900ecb3795cf4be28e076e9ae8594e6fe Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 11 Aug 2019 14:48:11 -0400 Subject: [PATCH] 2.0.1+1 --- CHANGELOG.md | 3 +++ example/main.dart | 46 ++++++++++++++++++++---------------------- lib/src/matchers.dart | 2 +- lib/src/validator.dart | 2 +- pubspec.yaml | 2 +- web/main.dart | 6 +++--- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc02b51..78b8e081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.1+1 +* Fix bug in the implementation of `maxLength`. + # 2.0.1 * Patch for updated body parsing. diff --git a/example/main.dart b/example/main.dart index a94dfea9..af500750 100644 --- a/example/main.dart +++ b/example/main.dart @@ -1,29 +1,27 @@ import 'package:angel_validate/angel_validate.dart'; main() { - var bio = new Validator({ - 'age*': [isInt, greaterThanOrEqualTo(0)], - 'birthYear*': isInt, - 'countryOfOrigin': isString - }); + var bio = new Validator({ + 'age*': [isInt, greaterThanOrEqualTo(0)], + 'birthYear*': isInt, + 'countryOfOrigin': isString + }); - var book = new Validator({ - 'title*': isString, - 'year*': [ - isNum, - (year) { - return year <= new DateTime.now().year; - } - ] - }); + var book = new Validator({ + 'title*': isString, + 'year*': [ + isNum, + (year) { + return year <= new DateTime.now().year; + } + ] + }); - var author = new Validator({ - 'bio*': bio, - 'books*': [ - isList, - everyElement(book) - ] - }, defaultValues: { - 'books': [] - }); -} \ No newline at end of file + // ignore: unused_local_variable + var author = new Validator({ + 'bio*': bio, + 'books*': [isList, everyElement(book)] + }, defaultValues: { + 'books': [] + }); +} diff --git a/lib/src/matchers.dart b/lib/src/matchers.dart index 2ba96302..93ded920 100644 --- a/lib/src/matchers.dart +++ b/lib/src/matchers.dart @@ -78,7 +78,7 @@ Matcher minLength(int length) => predicate( /// Limits the maximum length of a string. Matcher maxLength(int length) => predicate( - (value) => value is String && value.length >= length, + (value) => value is String && value.length <= length, 'a string no longer than $length character(s) long'); /// Asserts that for a key `x`, the context contains an identical item `x_confirmed`. diff --git a/lib/src/validator.dart b/lib/src/validator.dart index 80a8d400..06f25806 100644 --- a/lib/src/validator.dart +++ b/lib/src/validator.dart @@ -79,7 +79,7 @@ class Validator extends Matcher { requiredFields.add(fieldName); } - Iterable _iterable = + var _iterable = schema[keys] is Iterable ? schema[keys] : [schema[keys]]; var iterable = []; diff --git a/pubspec.yaml b/pubspec.yaml index e3cbc0e9..c42b015b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_validate description: Cross-platform request body validation library based on `matcher`. -version: 2.0.1 +version: 2.0.1+1 author: Tobe O homepage: https://github.com/angel-dart/validate environment: diff --git a/web/main.dart b/web/main.dart index 933f3ccf..08406f27 100644 --- a/web/main.dart +++ b/web/main.dart @@ -1,9 +1,9 @@ import 'dart:html'; import 'package:angel_validate/angel_validate.dart'; -final UListElement $errors = querySelector('#errors'); -final FormElement $form = querySelector('#form'); -final InputElement $blank = querySelector('[name="blank"]'); +final $errors = querySelector('#errors') as UListElement; +final $form = querySelector('#form') as FormElement; +final $blank = querySelector('[name="blank"]') as InputElement; final Validator formSchema = new Validator({ 'firstName*': [isString, isNotEmpty],