From 400d4544783db2e36da4a74cd46aa2580955c069 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 6 Apr 2024 18:11:49 +0800 Subject: [PATCH] enhance: a more adaptable regular expression for remote URLs (#61) --- src/Models/Remote.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Models/Remote.cs b/src/Models/Remote.cs index f58ae366..e3eaf36d 100644 --- a/src/Models/Remote.cs +++ b/src/Models/Remote.cs @@ -4,19 +4,17 @@ namespace SourceGit.Models { public partial class Remote { - - [GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")] - private static partial Regex regex1(); - + [GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+\.git$")] + private static partial Regex REG_HTTPS(); [GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-\.]+\.git$")] - private static partial Regex regex2(); + private static partial Regex REG_SSH1(); [GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")] - private static partial Regex regex3(); + private static partial Regex REG_SSH2(); private static readonly Regex[] URL_FORMATS = [ - regex1(), - regex2(), - regex3(), + REG_HTTPS(), + REG_SSH1(), + REG_SSH2(), ]; public string Name { get; set; }