From 157528acf72b33a003ab94b34d1be509e370221a Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 18 Oct 2018 19:40:00 +0900 Subject: [PATCH] [Modify] Throw exception --- websocket-sharp/Net/HttpUtility.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/websocket-sharp/Net/HttpUtility.cs b/websocket-sharp/Net/HttpUtility.cs index e19eb6ab..4c2f5e17 100644 --- a/websocket-sharp/Net/HttpUtility.cs +++ b/websocket-sharp/Net/HttpUtility.cs @@ -1141,14 +1141,23 @@ namespace WebSocketSharp.Net : InternalUrlDecode (bytes, 0, len, encoding ?? Encoding.UTF8); } - public static string UrlDecode (byte[] bytes, int offset, int count, Encoding encoding) + public static string UrlDecode ( + byte[] bytes, int offset, int count, Encoding encoding + ) { if (bytes == null) - return null; + throw new ArgumentNullException ("bytes"); var len = bytes.Length; - if (len == 0 || count == 0) + if (len == 0) { + if (offset != 0) + throw new ArgumentOutOfRangeException ("offset"); + + if (count != 0) + throw new ArgumentOutOfRangeException ("count"); + return String.Empty; + } if (offset < 0 || offset >= len) throw new ArgumentOutOfRangeException ("offset"); @@ -1156,7 +1165,11 @@ namespace WebSocketSharp.Net if (count < 0 || count > len - offset) throw new ArgumentOutOfRangeException ("count"); - return InternalUrlDecode (bytes, offset, count, encoding ?? Encoding.UTF8); + return count > 0 + ? InternalUrlDecode ( + bytes, offset, count, encoding ?? Encoding.UTF8 + ) + : String.Empty; } public static byte[] UrlDecodeToBytes (byte[] bytes)