normalizeUri static method

Uri normalizeUri(
  1. Uri uri
)

Normalizes a URI by ensuring it has a valid path and removing trailing slashes.

Implementation

static Uri normalizeUri(Uri uri) {
  String path = uri.path;
  if (!path.startsWith('/')) {
    path = '/$path';
  }
  if (path.length > 1 && path.endsWith('/')) {
    path = path.substring(0, path.length - 1);
  }
  if (path == uri.path) {
    return uri;
  }
  return uri.replace(path: path);
}