Skip to content

Commit 157528a

Browse files
committed
[Modify] Throw exception
1 parent 3a82d30 commit 157528a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

websocket-sharp/Net/HttpUtility.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,22 +1141,35 @@ public static string UrlDecode (byte[] bytes, Encoding encoding)
11411141
: InternalUrlDecode (bytes, 0, len, encoding ?? Encoding.UTF8);
11421142
}
11431143

1144-
public static string UrlDecode (byte[] bytes, int offset, int count, Encoding encoding)
1144+
public static string UrlDecode (
1145+
byte[] bytes, int offset, int count, Encoding encoding
1146+
)
11451147
{
11461148
if (bytes == null)
1147-
return null;
1149+
throw new ArgumentNullException ("bytes");
11481150

11491151
var len = bytes.Length;
1150-
if (len == 0 || count == 0)
1152+
if (len == 0) {
1153+
if (offset != 0)
1154+
throw new ArgumentOutOfRangeException ("offset");
1155+
1156+
if (count != 0)
1157+
throw new ArgumentOutOfRangeException ("count");
1158+
11511159
return String.Empty;
1160+
}
11521161

11531162
if (offset < 0 || offset >= len)
11541163
throw new ArgumentOutOfRangeException ("offset");
11551164

11561165
if (count < 0 || count > len - offset)
11571166
throw new ArgumentOutOfRangeException ("count");
11581167

1159-
return InternalUrlDecode (bytes, offset, count, encoding ?? Encoding.UTF8);
1168+
return count > 0
1169+
? InternalUrlDecode (
1170+
bytes, offset, count, encoding ?? Encoding.UTF8
1171+
)
1172+
: String.Empty;
11601173
}
11611174

11621175
public static byte[] UrlDecodeToBytes (byte[] bytes)

0 commit comments

Comments
 (0)