Skip to content

Commit

Permalink
Fix CoreFX test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesqo committed Jul 5, 2016
1 parent 1f9cd67 commit 4fd1bfe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/mscorlib/src/System/Text/ASCIIEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public override int GetByteCount(char[] chars, int index, int count)
[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(String chars)
{
// NOTE: If chars is null, this will throw an ArgumentNullException
// with the parameter name "s" rather than "chars"
return EncodingForwarder.GetByteCount(this, chars);
}

Expand All @@ -83,7 +81,6 @@ public override unsafe int GetByteCount(char* chars, int count)
public override int GetBytes(String chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
// NOTE: Will throw ArgumentNull of "s" is chars is null.
return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}

Expand Down Expand Up @@ -149,8 +146,6 @@ public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int
[System.Security.SecuritySafeCritical] // auto-generated
public override String GetString(byte[] bytes, int byteIndex, int byteCount)
{
// NOTE: If the byteIndex/byteCount parameters are invalid, this will
// throw an ArgumentOutOfRange for "index" or "count" instead of those names.
return EncodingForwarder.GetString(this, bytes, byteIndex, byteCount);
}

Expand Down
16 changes: 12 additions & 4 deletions src/mscorlib/src/System/Text/EncodingForwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public unsafe static int GetByteCount(Encoding encoding, string s)
Contract.Assert(encoding != null);
if (s == null)
{
throw new ArgumentNullException("s");
string paramName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the string chars
throw new ArgumentNullException(paramName);
}
Contract.EndContractBlock();

Expand Down Expand Up @@ -101,15 +102,18 @@ public unsafe static int GetBytes(Encoding encoding, string s, int charIndex, in
Contract.Assert(encoding != null);
if (s == null || bytes == null)
{
throw new ArgumentNullException(s == null ? "s" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars
throw new ArgumentNullException(s == null ? stringName : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
}
if (charIndex < 0 || charCount < 0)
{
throw new ArgumentOutOfRangeException(charIndex < 0 ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (s.Length - charIndex < charCount)
{
throw new ArgumentOutOfRangeException("s", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars
// Duplicate the above check since we don't want the overhead of a type check on the general path
throw new ArgumentOutOfRangeException(stringName, Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
}
if (byteIndex < 0 || byteIndex > bytes.Length)
{
Expand Down Expand Up @@ -293,7 +297,11 @@ public unsafe static string GetString(Encoding encoding, byte[] bytes, int index
}
if (index < 0 || count < 0)
{
throw new ArgumentOutOfRangeException(index < 0 ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
// ASCIIEncoding has different names for its parameters here (byteIndex, byteCount)
bool ascii = encoding is ASCIIEncoding;
string indexName = ascii ? "byteIndex" : "index";
string countName = ascii ? "byteCount" : "count";
throw new ArgumentOutOfRangeException(index < 0 ? indexName : countName, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (bytes.Length - index < count)
{
Expand Down
2 changes: 0 additions & 2 deletions src/mscorlib/src/System/Text/UTF8Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ public override int GetByteCount(char[] chars, int index, int count)
[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(String chars)
{
// NOTE: If chars is null, this will throw an ArgumentNullException
// with the parameter name "s" rather than "chars"
return EncodingForwarder.GetByteCount(this, chars);
}

Expand Down

0 comments on commit 4fd1bfe

Please sign in to comment.