Skip to content

ConvertTo-Html: assign HtmlEncode result to -Title#27103

Open
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
cuiweixie:fix-ConvertTo-Html-Title-HtmlEncode
Open

ConvertTo-Html: assign HtmlEncode result to -Title#27103
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
cuiweixie:fix-ConvertTo-Html-Title-HtmlEncode

Conversation

@cuiweixie
Copy link
Copy Markdown

Summary

Ensures -Title text is HTML-encoded in the generated document so characters such as <, >, &, and quotes do not break the <title> element or inject unintended markup.

Changes

  • Assign WebUtility.HtmlEncode(_title) back to _title in BeginProcessing.
  • Add a Pester regression test that compares the emitted <title> content to [System.Net.WebUtility]::HtmlEncode for the same input.

Testing

  • Invoke-Pester on test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 (new It block).

BeginProcessing called WebUtility.HtmlEncode(_title) but discarded the return value, so HTML special characters were not escaped in the document title element.

Add a Pester regression test that asserts the emitted <title> matches WebUtility.HtmlEncode output.
Copilot AI review requested due to automatic review settings March 27, 2026 17:53
@cuiweixie cuiweixie requested a review from a team as a code owner March 27, 2026 17:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes ConvertTo-Html -Title output so the generated <title> element is HTML-encoded, preventing special characters from breaking markup or injecting unintended content.

Changes:

  • Assign the WebUtility.HtmlEncode(_title) result back to _title during BeginProcessing.
  • Add a Pester regression test validating <title> contains the encoded form of the input title.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs Ensures _title is actually HTML-encoded before being emitted into the default <title> tag.
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 Adds regression coverage verifying encoded <title> output for special characters.

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.

2 participants