parseRouteUri function
- String location
Parses an absolute route path or external URI, rejecting invalid escapes.
Applications decide which external domains and schemes to accept.
Implementation
Uri parseRouteUri(String location) {
if (RegExp(r'%(?![0-9a-fA-F]{2})').hasMatch(location)) {
throw FormatException('Invalid percent escape in route', location);
}
final uri = Uri.parse(location);
if (uri.path.isNotEmpty && !uri.path.startsWith('/')) {
throw FormatException('Expected an absolute route path', location);
}
uri.pathSegments;
uri.queryParametersAll;
return uri.path.isEmpty ? uri.replace(path: '/') : uri;
}