From 2aba80cb750cc6fe1994ea52836b08ad5037f2f7 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sun, 16 Feb 2020 20:01:59 +0100 Subject: [PATCH] GitHostSetup: Use git_url_parse2 to try to verify the url This way if the url is invalid we will know before trying to clone, which happens much later during the process. --- lib/screens/githostsetup_clone_url.dart | 22 ++++++++++------------ pubspec.lock | 23 ++++++++++++++++++++++- pubspec.yaml | 1 + 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/screens/githostsetup_clone_url.dart b/lib/screens/githostsetup_clone_url.dart index 8f39b782..6151c56e 100644 --- a/lib/screens/githostsetup_clone_url.dart +++ b/lib/screens/githostsetup_clone_url.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:git_url_parse2/git_url_parse2.dart'; import 'package:function_types/function_types.dart'; import 'package:gitjournal/apis/githost_factory.dart'; @@ -184,22 +185,19 @@ class GitCloneUrlKnownProviderPageState } // Returns null when valid -String _isCloneUrlValid(String value) { - value = value.trim(); - if (value.isEmpty) { +String _isCloneUrlValid(String url) { + url = url.trim(); + if (url.isEmpty) { return 'Please enter some text'; } - if (value.startsWith('https://') || - value.startsWith('http://') || - value.startsWith('git://') || - value.startsWith('ssh+git://') || - value.startsWith('git+ssh://')) { - return 'Only SSH urls are currently accepted'; + + var result = gitUrlParse(url); + if (result == null) { + return 'Invalid Input'; } - RegExp regExp = RegExp(r".*@.*"); - if (!regExp.hasMatch(value)) { - return "Invalid Input"; + if (result.protocol != 'ssh') { + return 'Only SSH urls are currently accepted'; } return null; diff --git a/pubspec.lock b/pubspec.lock index 0fe7f20b..dbfe22c8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -224,6 +224,13 @@ packages: description: flutter source: sdk version: "0.0.0" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.0" fuchsia_remote_debug_protocol: dependency: transitive description: flutter @@ -243,6 +250,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.11" + git_url_parse2: + dependency: "direct main" + description: + name: git_url_parse2 + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1" glob: dependency: transitive description: @@ -306,6 +320,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.1+1" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" json_rpc_2: dependency: transitive description: @@ -753,5 +774,5 @@ packages: source: hosted version: "0.0.5" sdks: - dart: ">=2.5.0 <3.0.0" + dart: ">=2.7.0 <3.0.0" flutter: ">=1.12.13+hotfix.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 89f528b4..6694e382 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: yaml_serializer: ^0.0.5 connectivity: ^0.4.6+1 flutter_emoji: ">= 2.0.0" + git_url_parse2: ^0.0.1 dev_dependencies: flutter_launcher_icons: "^0.7.2"