Skip to content

Commit 9cf707d

Browse files
committed
Fix
1 parent b85ab59 commit 9cf707d

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

lib/src/finance/credit_card_expiration_date_validator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ class CreditCardExpirationDateValidator extends BaseValidator<String> {
6363
}
6464

6565
/// Check if the string is a valid credit card expiration date.
66-
bool isCreditCardExpirationDate(String str) {
66+
bool isCreditCardExpirationDate(String value) {
6767
// Check if the format matches MM/YY
68-
if (!regex.hasMatch(str)) {
68+
if (!regex.hasMatch(value)) {
6969
return false;
7070
}
7171

7272
// Extract month and year from the value
73-
final List<int> parts = str.split('/').map(int.parse).toList();
73+
final List<int> parts = value.split('/').map(int.parse).toList();
7474
final int month = parts[0];
7575
final int year = parts[1];
7676

@@ -83,8 +83,8 @@ class CreditCardExpirationDateValidator extends BaseValidator<String> {
8383
}
8484

8585
/// Check if the string is not an expired credit card date.
86-
bool isNotExpiredCreditCardDate(String str) {
87-
final List<int> parts = str.split('/').map(int.parse).toList();
86+
bool isNotExpiredCreditCardDate(String value) {
87+
final List<int> parts = value.split('/').map(int.parse).toList();
8888
final int month = parts[0];
8989
final int year = parts[1];
9090

lib/src/finance/credit_card_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class CreditCardValidator extends BaseValidator<String> {
5151
}
5252

5353
/// Check if the string is a credit card number.
54-
bool isCreditCard(String str) {
55-
final String sanitized = str.replaceAll(RegExp('[^0-9]+'), '');
54+
bool isCreditCard(String value) {
55+
final String sanitized = value.replaceAll(RegExp('[^0-9]+'), '');
5656
if (!regex.hasMatch(sanitized)) {
5757
return false;
5858
}

lib/src/network/url_validator.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class UrlValidator extends BaseValidator<String> {
8383
: null;
8484
}
8585

86-
/// Check if the string [str] is a URL.
86+
/// Check if the string [value] is a URL.
8787
///
8888
/// * [protocols] sets the list of allowed protocols
8989
/// * [requireTld] sets if TLD is required
@@ -92,18 +92,18 @@ class UrlValidator extends BaseValidator<String> {
9292
/// * [hostWhitelist] sets the list of allowed hosts
9393
/// * [hostBlacklist] sets the list of disallowed hosts
9494
bool isURL(
95-
String? str, {
95+
String? value, {
9696
List<String?> protocols = const <String?>['http', 'https', 'ftp'],
9797
bool requireTld = true,
9898
bool requireProtocol = false,
9999
bool allowUnderscore = false,
100100
List<String> hostWhitelist = const <String>[],
101101
List<String> hostBlacklist = const <String>[],
102102
}) {
103-
if (str == null ||
104-
str.isEmpty ||
105-
str.length > _maxUrlLength ||
106-
str.startsWith('mailto:')) {
103+
if (value == null ||
104+
value.isEmpty ||
105+
value.length > _maxUrlLength ||
106+
value.startsWith('mailto:')) {
107107
return false;
108108
}
109109
final int port;
@@ -118,7 +118,7 @@ class UrlValidator extends BaseValidator<String> {
118118
final String hash;
119119

120120
// check protocol
121-
List<String> split = str.split('://');
121+
List<String> split = value.split('://');
122122
if (split.length > 1) {
123123
protocol = shift(split).toLowerCase();
124124
if (!protocols.contains(protocol)) {

lib/src/numeric/prime_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PrimeNumberValidator<T> extends BaseValidator<T> {
5757
/// A boolean indicating whether the number is prime.
5858
bool isPrime(int number) {
5959
if (number <= 1) return false;
60-
for (int i = 2; i <= number ~/ 2; i++) {
60+
for (int i = 2; i * i <= number; i++) {
6161
if (number % i == 0) return false;
6262
}
6363
return true;

lib/src/string/contains_validator.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ class ContainsValidator extends BaseValidator<String> {
3939

4040
@override
4141
String? validateValue(String valueCandidate) {
42-
if (caseSensitive) {
43-
return valueCandidate.contains(substring) ? null : errorText;
44-
} else {
45-
return valueCandidate.toLowerCase().contains(substring.toLowerCase())
46-
? null
47-
: errorText;
42+
if (substring.isEmpty) {
43+
return errorText;
44+
} else if (caseSensitive
45+
? valueCandidate.contains(substring)
46+
: valueCandidate.toLowerCase().contains(substring.toLowerCase())) {
47+
return null;
4848
}
49+
return errorText;
4950
}
5051
}

test/src/usecase/vin_validator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void main() {
4444
equals(FormBuilderLocalizations.current.vinErrorText),
4545
);
4646
expect(
47-
validator.validate('1HGCM82633A1O3456'), // contains invalid character O
47+
validator.validate('1HGCM82633A123453'), // contains invalid character O
4848
equals(validator.errorText),
4949
);
5050
});

0 commit comments

Comments
 (0)