Fix Windows PowerShell 5.1 import failure from non-ASCII module source (#1603) - #1611
eduardarbona (earbona23) wants to merge 1 commit into
Conversation
microsoftgraph#1603) The per-cmdlet source files under the Applications and Beta.Applications modules contained non-ASCII characters (the arrow "->", em/en dashes, and check marks) inside comments and Write-Host/Write-Verbose strings. These files are concatenated without a BOM into the shipped .psm1. Windows PowerShell 5.1 decodes a BOM-less file using the system ANSI code page instead of UTF-8, so each multi-byte character turns into stray quote characters that unbalance the surrounding strings. The parser then fails with "Missing closing ')' in expression" and "The string is missing the terminator", and Import-Module aborts. PowerShell 7 (Core) reads BOM-less files as UTF-8, which is why CI and PowerShell 7 users never saw the break. Replace the non-ASCII characters with ASCII equivalents so the generated module parses identically under every encoding. Two Users cmdlet files carried the same non-ASCII-without-BOM hazard (a curly apostrophe in a HelpMessage) and are cleaned as well. Add a Pester regression test that fails if any module source file reintroduces non-ASCII bytes. Fixes microsoftgraph#1603
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Learn Build status updates of commit 0b53622: ❌ Validation status: errorsPlease follow instructions here which may help to resolve issue.
For more details, please refer to the build report. Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them. |
|
Flagging that the red The failure is The same status is red on every recent open PR in this repo (#1601, #1572, #1529), so it looks like a docset configuration issue rather than per-PR validation. Happy to rebase if a fix lands. |
Description
Import-Module Microsoft.Entra.Applications(andMicrosoft.Entra.Beta.Applications) throws parser errors on Windows PowerShell 5.1 in 1.3.0, as reported in #1603.Root cause
The shipped
.psm1is assembled by concatenating the per-cmdlet.ps1source files and is written without a BOM. Several of the new AgentId / Blueprint / MCPServer source files contain non-ASCII characters (→, em/en dashes,✓) in comments and inWrite-Host/Write-Verbosestrings.Windows PowerShell 5.1 decodes a BOM-less file with the system ANSI code page rather than UTF-8, so each multi-byte character becomes a stray curly-quote that unbalances the surrounding string. The parser then fails with
Missing closing ')' in expressionandThe string is missing the terminator, and the import aborts. PowerShell 7 reads BOM-less files as UTF-8, so CI and PowerShell 7 users never hit this.Fix
→→->, dashes→-,✓→[OK]). ASCII parses identically under every encoding.Userscmdlet files carried the same non-ASCII-without-BOM hazard (a curly apostrophe in aHelpMessage); they are cleaned as well so the source tree is fully ASCII. Those two do not break the import, only garble help text, but they trip the same PSScriptAnalyzer rule.test/Entra/SourceFileEncoding.Tests.ps1, a Pester regression test that fails if anymodule/**/*.ps1reintroduces non-ASCII bytes.Testing
Invoke-ScriptAnalyzerno longer reportsPSUseBOMForUnicodeEncodedFileon any of the changed files (16 findings removed, no new findings).Fixes #1603