From 4d6ea9d707de1c6e995ab2acd882bced4efc7685 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 22 May 2011 19:08:14 +0100 Subject: [PATCH] Do host name checking the same way in back- and frontend --- SparkleLib/SparkleRepoBase.cs | 2 +- SparkleShare/SparkleController.cs | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 34d51f6a..af04e160 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -53,7 +53,7 @@ namespace SparkleLib { public string Domain { get { - Regex regex = new Regex (@"(@|://)([a-z0-9\.]+)/"); + Regex regex = new Regex (@"(@|://)([a-z0-9\.]+)(/|:)"); Match match = regex.Match (Url); if (match.Success) diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 6db7f325..179132cb 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -968,12 +968,14 @@ namespace SparkleShare { { SparkleHelpers.DebugInfo ("Controller", "Formed URL: " + url); - // TODO: GetDomain method - string host = url.Substring (url.IndexOf ("@") + 1); - if (host.Contains (":")) - host = host.Substring (0, host.IndexOf (":")); - else - host = host.Substring (0, host.IndexOf ("/")); + string host = GetHost (url); + + if (String.IsNullOrEmpty (host)) { + if (FolderFetchError != null) + FolderFetchError (); + + return; + } DisableHostKeyCheckingForHost (host); @@ -1053,7 +1055,19 @@ namespace SparkleShare { Byte[] encoded_bytes = md5.ComputeHash (bytes); return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); } - + + + private string GetHost (string url) + { + Regex regex = new Regex (@"(@|://)([a-z0-9\.]+)(/|:)"); + Match match = regex.Match (url); + + if (match.Success) + return match.Groups [2].Value; + else + return null; + } + // Checks whether there are any folders syncing and // quits if safe