fix(mobile): allow URL validation to pass when scheme is not provided (#30142)

* fix(mobile): allow URL validation to pass when scheme is not provided

* Do normalize and validate in the same step
This commit is contained in:
Adam Gastineau 2026-07-23 07:16:48 -07:00 committed by GitHub
parent ceef4037f1
commit a0a0aa3f3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 20 deletions

View file

@ -2,12 +2,31 @@ import 'package:immich_mobile/domain/models/store.model.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:punycode/punycode.dart';
String sanitizeUrl(String url) {
/// Normalizes a server URL, guaranteeing that it has a schema and no trailing slashes
String normalizeServerUrl(String url) {
final trimmedUrl = url.trim();
// Add schema if none is set
final urlWithSchema = url.trimLeft().startsWith(RegExp(r"https?://")) ? url : "https://$url";
final urlWithSchema = trimmedUrl.contains('://') ? trimmedUrl : "https://$trimmedUrl";
// Remove trailing slash(es)
return urlWithSchema.trimRight().replaceFirst(RegExp(r"/+$"), "");
return urlWithSchema.replaceFirst(RegExp(r"/+$"), "");
}
/// Validates a user-entered server URL
bool _validateServerUrl(String url) {
final parsedUrl = Uri.tryParse(url);
return parsedUrl != null && parsedUrl.scheme.startsWith(RegExp(r'^https?$')) && parsedUrl.host.isNotEmpty;
}
/// Normalizes and validates that a server URL is supported
bool normalizeAndValidateServerUrl(String? url) {
if (url == null || url.isEmpty) {
return true;
}
final normalizedUrl = normalizeServerUrl(url);
return _validateServerUrl(normalizedUrl);
}
String? getServerUrl() {