createSafeUrl static method

String createSafeUrl(
  1. String url
)

Implementation

static String createSafeUrl(String url) {
  if (url.isEmpty) return url;

  String safeUrl = url;
  if (!safeUrl.contains('://')) {
    safeUrl = url.replaceAll('/', '').replaceAll(':', '');
    safeUrl = '$safeUrl://';
  } else {
    final parts = safeUrl.split('://');
    if (parts.last.isNotEmpty && parts.last != 'wc') {
      if (!safeUrl.endsWith('/')) {
        return '$safeUrl/';
      }
      return safeUrl;
    } else {
      safeUrl = url.replaceFirst('://wc', '://');
    }
  }
  return safeUrl;
}