Change cleanUpUrl name

This commit is contained in:
shilangyu 2021-04-06 10:56:21 +02:00
parent fbb8ff3a33
commit 88e1f8324f
2 changed files with 7 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class AddInstancePage extends HookWidget {
final debounce = useDebounce(() async {
if (prevInput == instanceController.text) return;
final inst = cleanUpUrl(instanceController.text);
final inst = normalizeInstanceHost(instanceController.text);
if (inst.isEmpty) {
isSite.value = null;
return;
@ -47,7 +47,7 @@ class AddInstancePage extends HookWidget {
instanceController.removeListener(debounce);
};
}, []);
final inst = cleanUpUrl(instanceController.text);
final inst = normalizeInstanceHost(instanceController.text);
handleOnAdd() async {
try {
await accountsStore.addInstance(inst, assumeValid: true);

View File

@ -1,9 +1,9 @@
/// Returns host of a url without a leading 'www.' or protocol if present also
/// removes trailing '/'
String cleanUpUrl(String url) {
/// Returns a normalized host of a (maybe) url without a leading www.
String normalizeInstanceHost(String maybeUrl) {
try {
return urlHost(url.startsWith('https://') ? url : 'https://$url');
} on FormatException catch (_) {
return urlHost(
maybeUrl.startsWith('https://') ? maybeUrl : 'https://$maybeUrl');
} on FormatException {
return '';
}
}