Skip to content

Fix Import-MamlHelp failing to read <command:uri> in related links#854

Open
teramako wants to merge 2 commits into
PowerShell:mainfrom
teramako:fix_load_commandUri
Open

Fix Import-MamlHelp failing to read <command:uri> in related links#854
teramako wants to merge 2 commits into
PowerShell:mainfrom
teramako:fix_load_commandUri

Conversation

@teramako

@teramako teramako commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

PR Summary

This PR fixes an issue where Import-MamlHelp fails to read <command:uri> in <maml:navigationLink> and throws an XmlException.

PowerShell’s built-in MAML reader (Get-Help / Show-HelpPreview) correctly reads <command:uri> because it matches only the local-name uri and does not require the maml: namespace. platyPS should maintain compatibility with this behavior.

Older versions of platyPS (prior to 1.0.2) also emitted <command:url> in Export-MamlCommandHelp, so Import-MamlHelp must support this legacy format to ensure round‑trip compatibility.

This PR updates TransformMaml.ReadRelatedLinks to safely read both <maml:uri> and <command:uri> using ReadSubtree(), and removes the incorrect ReadEndElement() call that caused the XmlException.

PR Context

Fixes #852

Summary of changes

  • Add support for <command:uri> in related links (legacy MAML format)
  • Use ReadSubtree() to safely iterate navigationLink contents
  • Read both <maml:uri> and <command:uri> for compatibility with PowerShell’s MAML reader
  • Remove incorrect ReadEndElement() call that caused XmlException
  • Add failing test (command:uri-in-related-links.xml) and ensure it passes after the fix
  • Add comments explaining legacy compatibility and future removal conditions

Why this change is needed

Import-MamlHelp currently crashes when <command:uri> is present, even though PowerShell itself reads such MAML files without issue.
This breaks compatibility with legacy help content and prevents round‑trip conversion for modules that still use the older format.

This PR restores compatibility and aligns platyPS with PowerShell’s behavior.


This change is Reviewable

teramako added 2 commits July 10, 2026 22:49
…dLinks

Legacy MAML help may be written using `<command:uri>`. PowerShell's
built-in MAML reader (Get-Help / Show-HelpPreview) correctly reads
`<command:uri>` because it matches only the local-name `uri` and does
not require the `maml:` namespace. platyPS should maintain compatibility
with this behavior.

Older versions of platyPS (prior to 1.0.2) emitted `<command:url>` in
Export-MamlCommandHelp, so Import-MamlHelp must support this legacy
format to ensure round-trip compatibility.

The XmlException occurs because TransformMaml.ReadRelatedLinks calls
ReadEndElement() even when the reader is not positioned at an end
element. This happens whenever `<maml:uri>` is missing, regardless of
PR PowerShell#849. This is a long-standing reader-side bug.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import-MamlHelp fails to read <command:uri> and throws XmlException

1 participant