Skip to content

Commit 90aa11f

Browse files
GrabYourPitchforksJacksondr5
authored andcommitted
Revert "Fix resx test name mangling logic" (dotnet#39644)
* Revert "Fix resx test name mangling logic" This reverts commit 6af0d0e. * Add comment warning not to change this code
1 parent 7dbaf67 commit 90aa11f

File tree

2 files changed

+8
-43
lines changed

2 files changed

+8
-43
lines changed

src/libraries/System.Resources.Extensions/tests/TestData.cs

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,15 @@ public override void BindToName(Type serializedType, out string assemblyName, ou
303303
// workaround for https://github.com/dotnet/runtime/issues/31289
304304
assemblyQualifiedTypeName = assemblyQualifiedTypeName.Replace(s_coreAssemblyName, s_mscorlibAssemblyName);
305305

306-
if (TryDeconstructFullyQualifiedTypeName(assemblyQualifiedTypeName, out string newTypeName, out assemblyName))
306+
// The logic below is intentionally incorrect. Generic type names like System.Collections.Generic.List`1[[System.String, ...]]
307+
// will be split on the first comma, causing unbalanced [[ and ]] in the resulting substrings. This is for compatibility
308+
// with the existing incorrect logic in Full Framework.
309+
310+
int pos = assemblyQualifiedTypeName.IndexOf(',');
311+
if (pos > 0 && pos < assemblyQualifiedTypeName.Length - 1)
307312
{
313+
assemblyName = assemblyQualifiedTypeName.Substring(pos + 1).TrimStart();
314+
string newTypeName = assemblyQualifiedTypeName.Substring(0, pos);
308315
if (!string.Equals(newTypeName, serializedType.FullName, StringComparison.InvariantCulture))
309316
{
310317
typeName = newTypeName;
@@ -319,48 +326,6 @@ public override Type BindToType(string assemblyName, string typeName)
319326
// We should never be using this binder during Deserialization
320327
throw new NotSupportedException($"{nameof(TypeNameManglingSerializationBinder)}.{nameof(BindToType)} should not be used during testing.");
321328
}
322-
323-
private static bool TryDeconstructFullyQualifiedTypeName(string assemblyQualifiedTypeName, out string typeName, out string assemblyName)
324-
{
325-
// Skip over all generic arguments in the assembly-qualified type name.
326-
327-
int genericDepth = 0;
328-
int i;
329-
for (i = 0; i < assemblyQualifiedTypeName.Length; i++)
330-
{
331-
switch (assemblyQualifiedTypeName[i])
332-
{
333-
case '[':
334-
checked { genericDepth++; }
335-
break;
336-
337-
case ']':
338-
checked { genericDepth--; }
339-
break;
340-
341-
case ',' when genericDepth == 0:
342-
goto AfterLoop;
343-
344-
default:
345-
continue;
346-
}
347-
}
348-
349-
AfterLoop:
350-
351-
if (i < assemblyQualifiedTypeName.Length - 1)
352-
{
353-
// Found a proper fully-qualified type name with assembly!
354-
typeName = assemblyQualifiedTypeName.Substring(0, i);
355-
assemblyName = assemblyQualifiedTypeName.Substring(i + 1).Trim();
356-
return true;
357-
}
358-
359-
// Couldn't find an assembly after the type name.
360-
typeName = default;
361-
assemblyName = default;
362-
return false;
363-
}
364329
}
365330
}
366331
}
-644 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)