imporved uri aprsing for localhost and ports
This commit is contained in:
@@ -28,10 +28,21 @@ Uri? tryParseUrl(String? input, {bool eagerParsing = false}) {
|
|||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
if (uri.authority.isEmpty && eagerParsing) {
|
if (uri.authority.isEmpty && eagerParsing) {
|
||||||
if (uri.pathSegments.isNotEmpty) {
|
if (uri.pathSegments.isNotEmpty) {
|
||||||
if (_domainRegex.hasMatch(uri.pathSegments.first)) {
|
int? port;
|
||||||
uri = Uri.tryParse('https://$input');
|
var firstSegment = uri.pathSegments.first;
|
||||||
} else if (InternetAddress.tryParse(uri.pathSegments.first) != null) {
|
|
||||||
uri = Uri.tryParse('https://$input');
|
//When there is no scheme while aprsing, the port becomse the first segment because : is treated as delimeter
|
||||||
|
if (int.tryParse(firstSegment) case final int segmentPort) {
|
||||||
|
port = segmentPort;
|
||||||
|
firstSegment = uri.scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_domainRegex.hasMatch(firstSegment)) {
|
||||||
|
uri = Uri.tryParse('https://$input')?.replace(port: port);
|
||||||
|
} else if (firstSegment == 'localhost') {
|
||||||
|
uri = Uri.tryParse('https://$input')?.replace(port: port);
|
||||||
|
} else if (InternetAddress.tryParse(firstSegment) != null) {
|
||||||
|
uri = Uri.tryParse('https://$input')?.replace(port: port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user