Skip to content

Commit d6f54ff

Browse files
committed
made url validator case insensitive
1 parent 7a103b1 commit d6f54ff

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/src/utils/validators.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ RegExp _ipv6 =
1010
RegExp _creditCard = RegExp(
1111
r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$');
1212

13+
int _maxUrlLength = 2083;
14+
1315
/// check if the string [str] is an email
1416
bool isEmail(String str) {
1517
return _email.hasMatch(str.toLowerCase());
@@ -32,7 +34,7 @@ bool isURL(String? str,
3234
List<String> hostBlacklist = const []}) {
3335
if (str == null ||
3436
str.isEmpty ||
35-
str.length > 2083 ||
37+
str.length > _maxUrlLength ||
3638
str.startsWith('mailto:')) {
3739
return false;
3840
}
@@ -43,7 +45,7 @@ bool isURL(String? str,
4345
// check protocol
4446
var split = str.split('://');
4547
if (split.length > 1) {
46-
protocol = shift(split);
48+
protocol = shift(split)!.toLowerCase();
4749
if (!protocols.contains(protocol)) {
4850
return false;
4951
}
@@ -94,7 +96,7 @@ bool isURL(String? str,
9496
// check hostname
9597
hostname = split.join('@');
9698
split = hostname.split(':');
97-
host = shift(split)!;
99+
host = shift(split)!.toLowerCase();
98100
if (split.isNotEmpty) {
99101
portStr = split.join(':');
100102
try {

0 commit comments

Comments
 (0)