Repository navigation
Fix NullReferenceException in manifest rules on .psd1 files with non-string keys - #2306
Open
David Dashti (Dashtid) wants to merge 1 commit into
Open
David Dashti (Dashtid) wants to merge 1 commit into
David Dashti (Dashtid) wants to merge 1 commit into
Conversation
IsModuleManifest threw a NullReferenceException on a .psd1 whose
top-level hashtable has a key that is not a string constant, such as
the data file @{ 0 = 'OK' }: GetMapFromHashtableAst returns null for
such a key, and the map was used without a check. The manifest rules
that call it, PSAvoidUsingDeprecatedManifestFields,
PSMissingModuleManifestField and PSUseToExportFieldsInManifest,
reported this as a rule error, and so did
PSDSCUseIdenticalMandatoryParametersForDSC.
Return false in that case, as the method did when 2f69abf added it.
David Dashti (Dashtid)
requested review from
a team and
Christoph Bergmeister (bergmeister)
as code owners
November 30, 2026 22:09
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change addressing non-string keys in PowerShell data files.
No open issues 🎉
What changed in this PR
Fixes #2305 by preventing manifest rules from throwing NullReferenceException when a .psd1 data file contains non-string top-level keys.
Changes:
- Adds a null guard to
Helper.IsModuleManifest, so these data files are not classified as module manifests. - Adds an integer-key fixture and regression tests confirming all three manifest rules produce neither errors nor diagnostics.
| File | Description |
|---|---|
Tests/Rules/UseToExportFieldsInManifest.tests.ps1 |
Adds regression coverage for the export-fields rule. |
Tests/Rules/TestManifest/PowerShellDataFileNonStringKey.psd1 |
Adds a shared data-file fixture with integer keys. |
Tests/Rules/AvoidUsingDeprecatedManifestFields.tests.ps1 |
Adds regression coverage for the deprecated-fields rule. |
Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 |
Adds regression coverage for the missing-manifest-field rule. |
Engine/Helper.cs |
Returns false when hashtable-to-map conversion returns null. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
PSAvoidUsingDeprecatedManifestFields,PSMissingModuleManifestFieldandPSUseToExportFieldsInManifestno longer throw a NullReferenceException on a.psd1whose top-level hashtable has a non-string key, such as@{ 0 = 'OK' }.Helper.IsModuleManifestnow returns false when such a key makesGetMapFromHashtableAstreturn null, which also fixes the same error inPSDSCUseIdenticalMandatoryParametersForDSC. Each manifest rule's tests check a data file with integer keys.PR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.Claude helped me write this and the issue, and I reviewed every line before sending.