Add support for inline XML format data in Update-FormatData#27713
Open
eevaal wants to merge 3 commits into
Open
Add support for inline XML format data in Update-FormatData#27713eevaal wants to merge 3 commits into
eevaal wants to merge 3 commits into
Conversation
Addresses PowerShell#7845 by allowing Update-FormatData to accept format data directly as XML strings using the -PrependFormatData and -AppendFormatData parameters. - Adds FormatDataXml property and constructor to SessionStateFormatEntry. - Updates TypeInfoDataBaseLoader to parse format data XML from strings without disk I/O. - Plumbs the inline XML capabilities into UpdateFormatDataCommand through TypeInfoDataBaseManager. - Adds unit tests covering new parameters.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
- Add blank lines before doc comments - Group fields before properties - Add Justification to SuppressMessage attributes - Use 'Gets or sets' in property summaries
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Update-FormatData to accept PS1XML formatting configuration as in-memory XML strings, enabling module authors to embed format data without shipping external .ps1xml files (addressing #7845).
Changes:
- Adds new
Update-FormatDataparameters-PrependFormatData/-AppendFormatDatafor inline format XML input. - Introduces
SessionStateFormatEntry.FormatDataXmland plumbing throughTypeInfoDataBaseManager/loader to load format data from XML strings. - Adds Pester coverage intended to validate loading views from inline XML.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1 |
Adds tests for loading format views from inline XML strings. |
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs |
Adds cmdlet parameters and populates InitialSessionState.Formats with inline XML entries. |
src/System.Management.Automation/engine/InitialSessionState.cs |
Adds FormatDataXml storage on SessionStateFormatEntry and cloning support. |
src/System.Management.Automation/utils/FormatAndTypeDataHelper.cs |
Adds support for carrying inline format XML through PSSnapInTypeAndFormatErrors. |
src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs |
Adds LoadXmlString(...) to parse/load formatting data from an XML string. |
src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataManager.cs |
Hooks inline XML loading into the format database load path. |
Comment on lines
+978
to
+980
| var doc = new System.Xml.XmlDocument(); | ||
| doc.LoadXml(PrependFormatData[i]); | ||
| newFormats.Add(new SessionStateFormatEntry(doc)); |
Comment on lines
+1018
to
+1020
| var doc = new System.Xml.XmlDocument(); | ||
| doc.LoadXml(appendFormatDataItem); | ||
| newFormats.Add(new SessionStateFormatEntry(doc)); |
Comment on lines
+369
to
+373
| else if (FormatDataXml != null) | ||
| { | ||
| var doc = new XmlDocument(); | ||
| doc.LoadXml(FormatDataXml); | ||
| entry = new SessionStateFormatEntry(doc); |
Comment on lines
+48
to
+53
| internal PSSnapInTypeAndFormatErrors(string psSnapinName, string formatDataXml, bool isXml) | ||
| { | ||
| this.psSnapinName = psSnapinName; | ||
| FormatDataXml = formatDataXml; | ||
| Errors = new ConcurrentBag<string>(); | ||
| } |
Security (High): Replace unsafe XmlDocument.LoadXml() with XmlReader using DtdProcessing.Prohibit and XmlResolver=null to prevent XXE and DTD entity expansion attacks. Fixed in Update-TypeData.cs (Prepend + Append) and InitialSessionState.Clone(). Tests (Medium): Fix variable scoping in Pester tests by passing xmlContent via param()/AddArgument() instead of string interpolation.
eevaal
force-pushed
the
feat/update-formatdata-xml
branch
from
July 22, 2026 19:40
ad795c7 to
9b555f4
Compare
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
This PR allows the
Update-FormatDatacmdlet to accept formatting configuration (PS1XML) directly from an in-memory string. It introduces two new string array parameters:-PrependFormatDataand-AppendFormatData.Under the hood:
FormatDataXmlproperty and anXmlDocumentconstructor toSessionStateFormatEntryfor secure encapsulation of the raw string.TypeInfoDataBaseLoaderto parse inline XML strings without requiring physical disk I/O.UpdateFormatDataCommandvia theTypeInfoDataBaseManager.-PrependFormatDataand-AppendFormatDatacorrectly load views.PR Context
Resolves #7845
Currently, module authors who use tools like
ModuleBuilderto pack their modules into a single.psm1file for better performance cannot easily embed their format data (.ps1xmlfile contents). They are forced to ship external.ps1xmlfiles alongside the module, which also complicates code signing (since the XML file must be signed separately).By allowing
Update-FormatDatato accept raw XML strings, module authors can now natively store and apply formatting rules entirely in memory.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header