From d1e05efbf133288f7c9882b44bc0a91f2a989f41 Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Thu, 6 Jul 2017 13:32:54 -0500 Subject: [PATCH] Added comma to the list of replaced characters in assemblyname (#4136) --- .../engine/parser/PSType.cs | 5 +++-- .../Scripting.Classes.RunPath.Tests.ps1 | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index 78a8c1de07..12e0bec2bf 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -1112,13 +1112,14 @@ namespace System.Management.Automation.Language var definedTypes = new HashSet(StringComparer.OrdinalIgnoreCase); - // First character is a special mark that allows us to cheaply ignore dynamic generated assemblies in ClrFacede.GetAssemblies() - // Two replaces at the end are for not-allowed characters. They are replaced by similar-looking chars. + // First character is a special mark that allows us to cheaply ignore dynamic generated assemblies in ClrFacade.GetAssemblies() + // The replaces at the end are for not-allowed characters. They are replaced by similar-looking chars. string assemblyName = ClrFacade.FIRST_CHAR_PSASSEMBLY_MARK + (string.IsNullOrWhiteSpace(rootAst.Extent.File) ? "powershell" : rootAst.Extent.File .Replace('\\', (char)0x29f9) .Replace('/', (char)0x29f9) + .Replace(',', (char)0x201a) .Replace(':', (char)0x0589)); var assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(assemblyName), diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 new file mode 100644 index 0000000000..d37635616c --- /dev/null +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -0,0 +1,20 @@ +Describe "Script with a class definition run path" -Tags "CI" { + + $TestCases = @( + @{ FileName = 'MyTest.ps1'; Name = 'path without a comma' } + @{ FileName = 'My,Test.ps1'; Name = 'path with a comma' } + ) + + It "Script with a class definition can run from a " -TestCases $TestCases { + param( $FileName ) + + $FilePath = Join-Path -Path $TestDrive -ChildPath $FileName + +@' +class MyClass { static [string]$MyProperty = 'Some value' } +[MyClass]::MyProperty +'@ | Out-File -FilePath $FilePath + + ( . $FilePath ) | Should Match 'Some value' + } +}