From ad0c305597473e7a2663f69ee7ad607eb6a78375 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sun, 22 Dec 2019 18:48:40 +0100 Subject: [PATCH] CloneUrlValidation: Our regexp is broken With AWS Code commit we get URLs of the form - ssh://APKAZLZA77YWDCWYRAC5@git-codecommit.eu-west-1.amazonaws.com/v1/repos/blah All our assumptions about how the URL should be are now invalid. It's best to just check for the presence of an '@' --- lib/screens/githostsetup_clone_url.dart | 52 ++++++++++--------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/lib/screens/githostsetup_clone_url.dart b/lib/screens/githostsetup_clone_url.dart index 56c2e92a..0e4ea38e 100644 --- a/lib/screens/githostsetup_clone_url.dart +++ b/lib/screens/githostsetup_clone_url.dart @@ -49,22 +49,7 @@ class GitCloneUrlPageState extends State { decoration: const InputDecoration( hintText: 'git@github.com:GitJournal/GitJournal.git', ), - validator: (String value) { - value = value.trim(); - if (value.isEmpty) { - return 'Please enter some text'; - } - if (value.startsWith('https://') || value.startsWith('http://')) { - return 'Only SSH urls are currently accepted'; - } - - RegExp regExp = RegExp(r"[a-zA-Z0-9.]+@[a-zA-Z0-9.-]+:.+"); - if (!regExp.hasMatch(value)) { - return "Invalid Input"; - } - - return null; - }, + validator: _isCloneUrlValid, focusNode: inputFormFocus, textInputAction: TextInputAction.done, onFieldSubmitted: (String _) => formSubmitted(), @@ -147,22 +132,7 @@ class GitCloneUrlKnownProviderPageState decoration: const InputDecoration( hintText: 'git@github.com:GitJournal/GitJournal.git', ), - validator: (String value) { - value = value.trim(); - if (value.isEmpty) { - return 'Please enter some text'; - } - if (value.startsWith('https://') || value.startsWith('http://')) { - return 'Only SSH urls are currently accepted'; - } - - RegExp regExp = RegExp(r"[a-zA-Z0-9.]+@[a-zA-Z0-9.]+:.+"); - if (!regExp.hasMatch(value)) { - return "Invalid Input"; - } - - return null; - }, + validator: _isCloneUrlValid, focusNode: inputFormFocus, textInputAction: TextInputAction.done, onFieldSubmitted: (String _) => formSubmitted(), @@ -208,3 +178,21 @@ class GitCloneUrlKnownProviderPageState ); } } + +// Returns null when valid +String _isCloneUrlValid(String value) { + value = value.trim(); + if (value.isEmpty) { + return 'Please enter some text'; + } + if (value.startsWith('https://') || value.startsWith('http://')) { + return 'Only SSH urls are currently accepted'; + } + + RegExp regExp = RegExp(r".*@.*"); + if (!regExp.hasMatch(value)) { + return "Invalid Input foo"; + } + + return null; +}