[Modify] Throw exception

This commit is contained in:
sta 2018-10-14 18:17:52 +09:00
parent 00a7de1508
commit 90e5db72f2

View File

@ -1189,20 +1189,26 @@ namespace WebSocketSharp.Net
public static byte[] UrlDecodeToBytes (byte[] bytes, int offset, int count) public static byte[] UrlDecodeToBytes (byte[] bytes, int offset, int count)
{ {
int len; if (bytes == null)
if (bytes == null || (len = bytes.Length) == 0) throw new ArgumentNullException ("bytes");
return bytes;
if (count == 0) var len = bytes.Length;
return new byte[0]; if (len == 0) {
if (offset != 0 || count != 0)
throw new ArgumentException ("An empty byte array.", "bytes");
return bytes;
}
if (offset < 0 || offset >= len) if (offset < 0 || offset >= len)
throw new ArgumentOutOfRangeException ("offset"); throw new ArgumentOutOfRangeException ("offset");
if (count < 0 || count > len - offset ) if (count < 0 || count > len - offset)
throw new ArgumentOutOfRangeException ("count"); throw new ArgumentOutOfRangeException ("count");
return InternalUrlDecodeToBytes (bytes, offset, count); return count > 0
? InternalUrlDecodeToBytes (bytes, offset, count)
: new byte[0];
} }
public static string UrlEncode (byte[] bytes) public static string UrlEncode (byte[] bytes)