Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ protected override void BeginProcessing()

if (!string.IsNullOrEmpty(_title))
{
WebUtility.HtmlEncode(_title);
_title = WebUtility.HtmlEncode(_title);
}

// This first line ensures w3c validation will succeed. However we are not specifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ Body Text
$returnString | Should -Be $expectedValue
}

It "ConvertTo-Html -Title HTML-encodes special characters in the document title" {
# Regression: BeginProcessing must assign WebUtility.HtmlEncode(_title) back to _title;
# otherwise the encode result is discarded and raw <, >, &, " appear in <title>.
$title = 'A <B> & C "D"'
$expectedInner = [System.Net.WebUtility]::HtmlEncode($title)
$returnString = ($customObject | ConvertTo-Html -Title $title) -join $newLine
$returnString | Should -Match "<title>$([regex]::Escape($expectedInner))</title>"
}

It "Test ConvertTo-Html pre and post" {
$returnString = ($customObject | ConvertTo-Html -PreContent "Before the object" -PostContent "After the object") -join $newLine
$expectedValue = normalizeLineEnds @"
Expand Down
Loading