From 9dcfc85c1cfd0b070e2becc03ae8659a557fe909 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 9 Mar 2017 15:35:30 +0900 Subject: [PATCH] [Modify] Throw exceptions --- websocket-sharp/Server/WebSocketServer.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 6621718d..1aa14b9c 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -1052,15 +1052,21 @@ namespace WebSocketSharp.Server ) where TBehavior : WebSocketBehavior { - string msg; - if (!checkServicePath (path, out msg)) { - _log.Error (msg); - return; - } + if (path == null) + throw new ArgumentNullException ("path"); - if (initializer == null) { - _log.Error ("'initializer' is null."); - return; + if (initializer == null) + throw new ArgumentNullException ("initializer"); + + if (path.Length == 0) + throw new ArgumentException ("An empty string.", "path"); + + if (path[0] != '/') + throw new ArgumentException ("Not an absolute path.", "path"); + + if (path.IndexOfAny (new[] { '?', '#' }) > -1) { + var msg = "It includes either or both query and fragment components."; + throw new ArgumentException (msg, "path"); } _services.Add (path, initializer);