8000 Added comma to replaced characters in assemblyname by TimCurwick · Pull Request #4136 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Added comma to replaced characters in assemblyname #4136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/System.Management.Automation/engine/parser/PSType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,13 +1112,14 @@ internal static Assembly DefineTypes(Parser parser, Ast rootAst, TypeDefinitionA

var definedTypes = new HashSet<string>(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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <Name>" -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'
}
}
0