From e8661442a89299673d9033fe426a447026705731 Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 27 May 2016 15:33:25 +0900 Subject: [PATCH] [Fix] Add a closing square bracket check Fix for a part of pull request #264. --- websocket-sharp/Net/HttpListenerPrefix.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/websocket-sharp/Net/HttpListenerPrefix.cs b/websocket-sharp/Net/HttpListenerPrefix.cs index a9cf859c..d7053a9d 100644 --- a/websocket-sharp/Net/HttpListenerPrefix.cs +++ b/websocket-sharp/Net/HttpListenerPrefix.cs @@ -126,15 +126,14 @@ namespace WebSocketSharp.Net var len = uriPrefix.Length; var startHost = uriPrefix.IndexOf (':') + 3; - var colon = uriPrefix.IndexOf (':', startHost, len - startHost); - var root = 0; - if (colon > 0) { - root = uriPrefix.IndexOf ('/', colon, len - colon); + var root = uriPrefix.IndexOf ('/', startHost, len - startHost); + + var colon = uriPrefix.LastIndexOf (':', root - 1, root - startHost - 1); + if (uriPrefix[root - 1] != ']' && colon > startHost) { _host = uriPrefix.Substring (startHost, colon - startHost); _port = (ushort) Int32.Parse (uriPrefix.Substring (colon + 1, root - colon - 1)); } else { - root = uriPrefix.IndexOf ('/', startHost, len - startHost); _host = uriPrefix.Substring (startHost, root - startHost); _port = (ushort) defaultPort; }