Skip to content

Commit 9f1a21f

Browse files
Merge pull request #69 from bjarn-hau/#67-fix-url-case-sensitivity
#67 fix url case sensitivity
2 parents 7a103b1 + 9ef2f84 commit 9f1a21f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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 {

test/form_builder_validators_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ void main() {
412412
expect(validator('www.google.com'), isNull);
413413
expect(validator('google.com'), isNull);
414414
expect(validator('http://google.com'), isNull);
415+
expect(validator('HTTPS://GOOGLE.COM'), isNull);
416+
expect(validator('GOOGLE.com'), isNull);
417+
expect(validator('GOOGLE.COM'), isNull);
418+
expect(validator('google.com/search?q=TEST'), isNull);
419+
expect(validator('google.com/search#MY_AWESOME_THING'), isNull);
415420
// Fail
416421
expect(validator('.com'), isNotNull);
417422
// Advanced overrides

0 commit comments

Comments
 (0)