mirror of https://github.com/quasar/Quasar.git
Improved error handling when parsing hosts list
This commit is contained in:
parent
ac9f386ec9
commit
173e600cf2
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using xClient.Core.Utilities;
|
||||
|
@ -12,14 +11,16 @@ public static List<Host> GetHostsList(string rawHosts)
|
|||
{
|
||||
List<Host> hostsList = new List<Host>();
|
||||
|
||||
if (string.IsNullOrEmpty(rawHosts)) return hostsList;
|
||||
|
||||
var hosts = rawHosts.Split(';');
|
||||
|
||||
foreach (var hostPart in from host in hosts where !string.IsNullOrEmpty(host) select host.Split(':'))
|
||||
foreach (var hostPart in from host in hosts where (!string.IsNullOrEmpty(host) && host.Contains(':')) select host.Split(':'))
|
||||
{
|
||||
if (hostPart.Length != 2 || hostPart[0].Length < 1 || hostPart[1].Length < 1) throw new Exception("Invalid host");
|
||||
if (hostPart.Length != 2 || hostPart[0].Length < 1 || hostPart[1].Length < 1) continue; // invalid, ignore host
|
||||
|
||||
ushort port;
|
||||
if (!ushort.TryParse(hostPart[1], out port)) throw new Exception("Invalid host");
|
||||
if (!ushort.TryParse(hostPart[1], out port)) continue; // invalid, ignore host
|
||||
|
||||
hostsList.Add(new Host { Hostname = hostPart[0], Port = port });
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using xServer.Core.Utilities;
|
||||
|
@ -12,16 +11,18 @@ public static List<Host> GetHostsList(string rawHosts)
|
|||
{
|
||||
List<Host> hostsList = new List<Host>();
|
||||
|
||||
if (string.IsNullOrEmpty(rawHosts)) return hostsList;
|
||||
|
||||
var hosts = rawHosts.Split(';');
|
||||
|
||||
foreach (var hostPart in from host in hosts where !string.IsNullOrEmpty(host) select host.Split(':'))
|
||||
foreach (var hostPart in from host in hosts where (!string.IsNullOrEmpty(host) && host.Contains(':')) select host.Split(':'))
|
||||
{
|
||||
if (hostPart.Length != 2 || hostPart[0].Length < 1 || hostPart[1].Length < 1) throw new Exception("Invalid host");
|
||||
if (hostPart.Length != 2 || hostPart[0].Length < 1 || hostPart[1].Length < 1) continue; // invalid, ignore host
|
||||
|
||||
ushort port;
|
||||
if (!ushort.TryParse(hostPart[1], out port)) throw new Exception("Invalid host");
|
||||
if (!ushort.TryParse(hostPart[1], out port)) continue; // invalid, ignore host
|
||||
|
||||
hostsList.Add(new Host {Hostname = hostPart[0], Port = port});
|
||||
hostsList.Add(new Host { Hostname = hostPart[0], Port = port });
|
||||
}
|
||||
|
||||
return hostsList;
|
||||
|
|
Loading…
Reference in New Issue