From 56c72fb4605f3bb0805c336eae22e90a50807e4f Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 14:26:04 -0500 Subject: [PATCH 1/8] Added comma to replaced characters in assemblyname --- src/System.Management.Automation/engine/parser/PSType.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index 78a8c1de078..5b3679bc3b5 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -1113,12 +1113,13 @@ internal static Assembly DefineTypes(Parser parser, Ast rootAst, TypeDefinitionA 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. + // 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), From 853ebccd61e7d34fd463d98a79ef8ecbbbc72c0d Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 14:56:27 -0500 Subject: [PATCH 2/8] Added Pester test for Classes runpath --- .../Scripting.Classes.RunPath.Tests.ps1 | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 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 00000000000..f45bb4df216 --- /dev/null +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -0,0 +1,42 @@ +Describe "Script with a class definition run path" { + + It "Script with a class definition can run from a path without a comma" { + + $FilePath = '.\MyTest.ps1' + + try { + 'class MyClass { [string]$MyProperty }; $True' | Out-File -FilePath $FilePath + $Success = . $FilePath + } + + catch { + $Success = $False + } + + finally { + Remove-Item -Path $FilePath + } + + $Success | Should Be $True + } + + It "Script with a class definition can run from a path with a comma" { + + $FilePath = '.\My,Test.ps1' + + try { + 'class MyClass { [string]$MyProperty }; $True' | Out-File -FilePath $FilePath + $Success = . $FilePath + } + + catch { + $Success = $False + } + + finally { + Remove-Item -Path $FilePath + } + + $Success | Should Be $True + } +} From 7eb13b1fac400e7d121d74c1443b559143f5ea4b Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 15:05:30 -0500 Subject: [PATCH 3/8] Added tags --- .../Language/Classes/Scripting.Classes.RunPath.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index f45bb4df216..07a235a7404 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Script with a class definition run path" { - It "Script with a class definition can run from a path without a comma" { + It "Script with a class definition can run from a path without a comma" -Tags "CI" { $FilePath = '.\MyTest.ps1' @@ -20,7 +20,7 @@ Describe "Script with a class definition run path" { $Success | Should Be $True } - It "Script with a class definition can run from a path with a comma" { + It "Script with a class definition can run from a path with a comma" -Tags "CI" { $FilePath = '.\My,Test.ps1' From 0190477c734e7a788812a945a0c2830e4cc753ca Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 15:12:50 -0500 Subject: [PATCH 4/8] Fixed tags --- .../Language/Classes/Scripting.Classes.RunPath.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index 07a235a7404..f93be776033 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -1,6 +1,6 @@ -Describe "Script with a class definition run path" { +Describe "Script with a class definition run path" -Tags "CI" { - It "Script with a class definition can run from a path without a comma" -Tags "CI" { + It "Script with a class definition can run from a path without a comma" { $FilePath = '.\MyTest.ps1' @@ -20,7 +20,7 @@ Describe "Script with a class definition run path" { $Success | Should Be $True } - It "Script with a class definition can run from a path with a comma" -Tags "CI" { + It "Script with a class definition can run from a path with a comma" { $FilePath = '.\My,Test.ps1' From 5d69d2c5c411c5db00a6f3c484711e8b58490a92 Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 17:21:26 -0500 Subject: [PATCH 5/8] Fixed typo in comments --- src/System.Management.Automation/engine/parser/PSType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/parser/PSType.cs b/src/System.Management.Automation/engine/parser/PSType.cs index 5b3679bc3b5..12e0bec2bf5 100644 --- a/src/System.Management.Automation/engine/parser/PSType.cs +++ b/src/System.Management.Automation/engine/parser/PSType.cs @@ -1112,7 +1112,7 @@ internal static Assembly DefineTypes(Parser parser, Ast rootAst, TypeDefinitionA var definedTypes = new HashSet(StringComparer.OrdinalIgnoreCase); - // First character is a special mark that allows us to cheaply ignore dynamic generated assemblies in ClrFacede.GetAssemblies() + // 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" From c3b823fe8bd811e9d6a0fc47e8c591b7d869d470 Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 18:20:49 -0500 Subject: [PATCH 6/8] Update Scripting.Classes.RunPath.Tests.ps1 --- .../Scripting.Classes.RunPath.Tests.ps1 | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index f93be776033..4f6a126a515 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -1,42 +1,21 @@ -Describe "Script with a class definition run path" -Tags "CI" { +Describe "Script with a class definition run path" { - It "Script with a class definition can run from a path without a comma" { + $TestCases = @( + @{ FileName = 'MyTest.ps1'; Name = 'path without a comma' } + @{ FileName = 'My,Test.ps1'; Name = 'path with a comma' } + ) - $FilePath = '.\MyTest.ps1' + It "Script with a class definition can run from a " -TestCases $TestCases { + param( $FileName ) - try { - 'class MyClass { [string]$MyProperty }; $True' | Out-File -FilePath $FilePath - $Success = . $FilePath - } + $FilePath = Join-Path -Path $TestDrive -ChildPath $FileName - catch { - $Success = $False - } +@' +class MyClass { static [string]$MyProperty = 'Some value' } +[MyClass]::MyProperty +'@ | Out-File -FilePath $FilePath - finally { - Remove-Item -Path $FilePath - } - - $Success | Should Be $True - } - - It "Script with a class definition can run from a path with a comma" { - - $FilePath = '.\My,Test.ps1' - - try { - 'class MyClass { [string]$MyProperty }; $True' | Out-File -FilePath $FilePath - $Success = . $FilePath - } - - catch { - $Success = $False - } - - finally { - Remove-Item -Path $FilePath - } - - $Success | Should Be $True + { . $FilePath } | Should Not Throw + ( . $FilePath ) | Should Match 'Some value' } } From 3d4cef57cec3a82a1decb464ac8773dabfd4865c Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Wed, 28 Jun 2017 18:31:24 -0500 Subject: [PATCH 7/8] Added tag. Again. --- .../Language/Classes/Scripting.Classes.RunPath.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index 4f6a126a515..2dbc82bf682 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Script with a class definition run path" { +Describe "Script with a class definition run path" -Tags "CI" { $TestCases = @( @{ FileName = 'MyTest.ps1'; Name = 'path without a comma' } From 88c0b9b19783532a70664d6f8cc1c350242fb22a Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Thu, 29 Jun 2017 10:35:43 -0500 Subject: [PATCH 8/8] Removed redundant test --- .../Language/Classes/Scripting.Classes.RunPath.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index 2dbc82bf682..d37635616c4 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -15,7 +15,6 @@ class MyClass { static [string]$MyProperty = 'Some value' } [MyClass]::MyProperty '@ | Out-File -FilePath $FilePath - { . $FilePath } | Should Not Throw ( . $FilePath ) | Should Match 'Some value' } }