Skip to content

Commit

Permalink
Added support for spaces and other special characters in method names…
Browse files Browse the repository at this point in the history
… into the ManagedNameUtilities (#2738)
  • Loading branch information
Haplois committed Feb 16, 2021
1 parent d788ad8 commit 3d0ed61
Show file tree
Hide file tree
Showing 30 changed files with 875 additions and 27 deletions.
14 changes: 7 additions & 7 deletions TestPlatform.sln
Expand Up @@ -82,17 +82,17 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}"
ProjectSection(SolutionItems) = preProject
scripts\build.ps1 = scripts\build.ps1
scripts\build.sh = scripts\build.sh
scripts\PortableToFullPdb.ps1 = scripts\PortableToFullPdb.ps1
scripts\stylecop.json = scripts\stylecop.json
scripts\stylecop.ruleset = scripts\stylecop.ruleset
scripts\stylecop.test.ruleset = scripts\stylecop.test.ruleset
scripts\test.ps1 = scripts\test.ps1
scripts\verify-sign.ps1 = scripts\verify-sign.ps1
scripts\test.sh = scripts\test.sh
scripts\verify-nupkgs.ps1 = scripts\verify-nupkgs.ps1
scripts\PortableToFullPdb.ps1 = scripts\PortableToFullPdb.ps1
scripts\verify-sign.ps1 = scripts\verify-sign.ps1
scripts\vsts-prebuild.ps1 = scripts\vsts-prebuild.ps1
scripts\write-release-notes.ps1 = scripts\write-release-notes.ps1
scripts\build.sh = scripts\build.sh
scripts\test.sh = scripts\test.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E344E0A2-7715-4C7F-BAF7-D64EA94CB19B}"
Expand Down Expand Up @@ -818,6 +818,8 @@ Global
{9EFCEFB5-253E-4DE2-8A70-821D7B8189DF} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{3A8080FB-9C93-45B9-8EB5-828DDC31FDF0} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{BFF7714C-E5A3-4EEB-B04B-5FA47F29AD03} = {020E15EA-731F-4667-95AF-226671E0C3AE}
{0D4DF78D-7E5F-4516-B19F-E6AA71A1DBF4} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{DED1590A-ED25-413B-8590-006A4DD5B2FD} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{E344E0A2-7715-4C7F-BAF7-D64EA94CB19B} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{DD9382B5-5EC4-4B3D-BEB7-95423731AE29} = {46250E12-4CF1-4051-B4A7-80C8C06E0068}
{156F8811-28BB-4EC7-87D9-434F10FB7DBE} = {46250E12-4CF1-4051-B4A7-80C8C06E0068}
Expand All @@ -829,7 +831,6 @@ Global
{CAE652AF-6801-425E-AAF3-AB20DE7DF88E} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3}
{FF80D706-8309-4E02-BAC0-D28B4CBCF600} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{DED1590A-ED25-413B-8590-006A4DD5B2FD} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{E141A226-CC0A-4F26-BD17-4AE427D81C3B} = {D27E1CB4-C641-4C6C-A140-EF5F6215AE29}
{376C19DE-31E2-4FF6-88FC-0D0D6233C999} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{3E698655-0701-482E-9AA7-F956F6337FC7} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999}
Expand All @@ -842,15 +843,14 @@ Global
{65A25D6E-C9CC-4F45-8925-04087AC82634} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB}
{D9A30E32-D466-4EC5-B4F2-62E17562279B} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{21DB138B-85B7-479E-91FE-01E0F972EC56} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{0D4DF78D-7E5F-4516-B19F-E6AA71A1DBF4} = {EE49F5DC-5835-4AE3-B3BA-8BDE0AD56330}
{8C068694-23A2-47A2-A0DD-DB82D0AF0142} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999}
{24C7683D-2607-4901-B8EB-83A57E49E93D} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999}
{69F5FF81-5615-4F06-B83C-FCF979BB84CA} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{236A71E3-01DA-4679-9DFF-16A8E079ACFF} = {5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF}
{41248B96-6E15-4E5E-A78F-859897676814} = {020E15EA-731F-4667-95AF-226671E0C3AE}
{074F5BD6-DC05-460B-B78F-044D125FD787} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{DCD0C39E-C78C-4A44-B0BD-7325254A2E97} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{DCD0C39E-C78C-4A44-B0BD-7325254A2E97} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999}
{2DE99835-A3A3-4922-82AD-6D10D284816D} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
6 changes: 6 additions & 0 deletions scripts/build.ps1
Expand Up @@ -122,6 +122,7 @@ $env:MSBUILD_VERSION = "15.0"
Write-Verbose "Setup build configuration."
$TPB_Solution = "TestPlatform.sln"
$TPB_TestAssets_Solution = Join-Path $env:TP_ROOT_DIR "test\TestAssets\TestAssets.sln"
$TPB_TestAssets_CILAssets = Join-Path $env:TP_ROOT_DIR "test\TestAssets\CILProject\CILProject.proj"
$TPB_TargetFramework45 = "net45"
$TPB_TargetFramework451 = "net451"
$TPB_TargetFramework472 = "net472"
Expand Down Expand Up @@ -277,6 +278,11 @@ function Invoke-Build
& $dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:TestPlatform.binlog
Write-Log ".. .. Build: Complete."

Write-Log ".. .. Build: Source: $TPB_TestAssets_CILAssets"
Write-Verbose "$dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild"
& $dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:"$($env:TP_ROOT_DIR)\CILAssets.binlog"
Write-Log ".. .. Build: Complete."

Set-ScriptFailedOnError

Write-Log "Invoke-Build: Complete. {$(Get-ElapsedTime($timer))}"
Expand Down
1 change: 1 addition & 0 deletions scripts/build/TestPlatform.Dependencies.props
Expand Up @@ -29,6 +29,7 @@
<FileSystemGlobbingVersion>1.1.1</FileSystemGlobbingVersion>

<NuGetFrameworksVersion>5.0.0</NuGetFrameworksVersion>
<ILAsmPackageVersion>5.0.0</ILAsmPackageVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>16.9.0-preview-4267359</TestPlatformExternalsVersion>
Expand Down
1 change: 1 addition & 0 deletions scripts/test.ps1
Expand Up @@ -207,6 +207,7 @@ function Invoke-Test
}
else
{
Write-Log ".. . $testContainerName test container found. ($testOutputPath)"
$testContainers += ,"$testContainerPath"
}
}
Expand Down
Expand Up @@ -3,9 +3,12 @@

namespace Microsoft.TestPlatform.AdapterUtilities.Helpers
{
using Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities;
using Microsoft.TestPlatform.AdapterUtilities.Resources;

using System;
using System.Globalization;
using System.Text;

internal static partial class ReflectionHelpers
{
Expand All @@ -17,5 +20,79 @@ private static void AssertSupport<T>(T obj, string methodName, string className)
throw new NotImplementedException(string.Format(Resources.MethodNotImplementedOnPlatform, className, methodName));
}
}

internal static string ParseEscapedString(string escapedString)
{
var stringBuilder = new StringBuilder();
var end = 0;
for (int i = 0; i < escapedString.Length; i++)
{
if (escapedString[i] == '\'')
{
stringBuilder.Append(escapedString, end, i - end);
end = i = ParseEscapedStringSegment(escapedString, i + 1, stringBuilder);
}
}

if (stringBuilder.Length == 0)
{
return escapedString;
}

if (end != 0 && end < escapedString.Length)
{
stringBuilder.Append(escapedString, end, escapedString.Length - end);
}

return stringBuilder.ToString();
}

// Unescapes a C# style escaped string.
private static int ParseEscapedStringSegment(string escapedStringSegment, int pos, StringBuilder stringBuilder)
{
for (int i = pos; i < escapedStringSegment.Length; i++)
{
switch (escapedStringSegment[i])
{
case '\\':
if (escapedStringSegment[i + 1] == 'u')
{
char c;

try
{
var code = escapedStringSegment.Substring(i + 2, 4);
c = (char)Convert.ToInt32(code, 16);
}
catch
{
throw new InvalidManagedNameException(
string.Format(CultureInfo.CurrentCulture, Resources.ErrorInvalidSequenceAt, escapedStringSegment, i)
);
}

stringBuilder.Append(c);
i += 5;
}
else
{
stringBuilder.Append(escapedStringSegment[i + 1]);
i += 1;
}

break;

case '\'':
return i + 1;

default:
stringBuilder.Append(escapedStringSegment[i]);
break;
}
}

string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorNoClosingQuote, escapedStringSegment);
throw new InvalidManagedNameException(message);
}
}
}

0 comments on commit 3d0ed61

Please sign in to comment.