Skip to content

Commit

Permalink
Revert "Fix resx test name mangling logic" (#39644)
Browse files Browse the repository at this point in the history
* Revert "Fix resx test name mangling logic"

This reverts commit 6af0d0e.

* Add comment warning not to change this code
  • Loading branch information
GrabYourPitchforks committed Jul 20, 2020
1 parent 36041c5 commit 25b6106
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions src/libraries/System.Resources.Extensions/tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,15 @@ public override void BindToName(Type serializedType, out string assemblyName, ou
// workaround for https://github.com/dotnet/runtime/issues/31289
assemblyQualifiedTypeName = assemblyQualifiedTypeName.Replace(s_coreAssemblyName, s_mscorlibAssemblyName);

if (TryDeconstructFullyQualifiedTypeName(assemblyQualifiedTypeName, out string newTypeName, out assemblyName))
// The logic below is intentionally incorrect. Generic type names like System.Collections.Generic.List`1[[System.String, ...]]
// will be split on the first comma, causing unbalanced [[ and ]] in the resulting substrings. This is for compatibility
// with the existing incorrect logic in Full Framework.

int pos = assemblyQualifiedTypeName.IndexOf(',');
if (pos > 0 && pos < assemblyQualifiedTypeName.Length - 1)
{
assemblyName = assemblyQualifiedTypeName.Substring(pos + 1).TrimStart();
string newTypeName = assemblyQualifiedTypeName.Substring(0, pos);
if (!string.Equals(newTypeName, serializedType.FullName, StringComparison.InvariantCulture))
{
typeName = newTypeName;
Expand All @@ -319,48 +326,6 @@ public override Type BindToType(string assemblyName, string typeName)
// We should never be using this binder during Deserialization
throw new NotSupportedException($"{nameof(TypeNameManglingSerializationBinder)}.{nameof(BindToType)} should not be used during testing.");
}

private static bool TryDeconstructFullyQualifiedTypeName(string assemblyQualifiedTypeName, out string typeName, out string assemblyName)
{
// Skip over all generic arguments in the assembly-qualified type name.

int genericDepth = 0;
int i;
for (i = 0; i < assemblyQualifiedTypeName.Length; i++)
{
switch (assemblyQualifiedTypeName[i])
{
case '[':
checked { genericDepth++; }
break;

case ']':
checked { genericDepth--; }
break;

case ',' when genericDepth == 0:
goto AfterLoop;

default:
continue;
}
}

AfterLoop:

if (i < assemblyQualifiedTypeName.Length - 1)
{
// Found a proper fully-qualified type name with assembly!
typeName = assemblyQualifiedTypeName.Substring(0, i);
assemblyName = assemblyQualifiedTypeName.Substring(i + 1).Trim();
return true;
}

// Couldn't find an assembly after the type name.
typeName = default;
assemblyName = default;
return false;
}
}
}
}
Binary file modified src/libraries/System.Resources.Extensions/tests/TestData.resources
Binary file not shown.

0 comments on commit 25b6106

Please sign in to comment.