Skip to content

Commit 9f1d2fc

Browse files
committed
Fix null issue
1 parent 7267c30 commit 9f1d2fc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/src/utils/helpers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Helper functions for validator and sanitizer.
22

3-
T? shift<T>(List<T> l) {
3+
T shift<T>(List<T> l) {
44
if (l.isNotEmpty) {
55
final first = l.first;
66
l.removeAt(0);
77
return first;
88
}
9-
return null;
9+
return null as T;
1010
}
1111

1212
Map merge(Map? obj, Map? defaults) {

lib/src/utils/validators.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool isURL(
4545
int port;
4646
String? protocol;
4747
String? auth;
48-
String? user;
48+
String user;
4949
String host;
5050
String hostname;
5151
String portStr;
@@ -56,7 +56,7 @@ bool isURL(
5656
// check protocol
5757
var split = str.split('://');
5858
if (split.length > 1) {
59-
protocol = shift(split)!.toLowerCase();
59+
protocol = shift(split).toLowerCase();
6060
if (!protocols.contains(protocol)) {
6161
return false;
6262
}
@@ -74,23 +74,23 @@ bool isURL(
7474
}
7575

7676
// check query params
77-
split = str!.split('?');
77+
split = str.split('?');
7878
str = shift(split);
7979
query = split.join('?');
8080
if (query.isNotEmpty && RegExp(r'\s').hasMatch(query)) {
8181
return false;
8282
}
8383

8484
// check path
85-
split = str!.split('/');
85+
split = str.split('/');
8686
str = shift(split);
8787
path = split.join('/');
8888
if (path.isNotEmpty && RegExp(r'\s').hasMatch(path)) {
8989
return false;
9090
}
9191

9292
// check auth type urls
93-
split = str!.split('@');
93+
split = str.split('@');
9494
if (split.length > 1) {
9595
auth = shift(split);
9696
if (auth?.contains(':') ?? false) {
@@ -107,7 +107,7 @@ bool isURL(
107107
// check hostname
108108
hostname = split.join('@');
109109
split = hostname.split(':');
110-
host = shift(split)!.toLowerCase();
110+
host = shift(split).toLowerCase();
111111
if (split.isNotEmpty) {
112112
portStr = split.join(':');
113113
try {

0 commit comments

Comments
 (0)