Fix XML escaping for EventName when saving to XML
Problem
PerfView was not properly escaping double quotes and other XML special characters in EventName when saving events to XML format. This resulted in invalid XML that could not be parsed correctly by XML parsers.
For example, an EventName like Enter" providername="Microsoft-Azure-Devices would generate invalid XML:
<Event EventName="Enter" providername="Microsoft-Azure-Devices" TimeMsec="783264.803" ProcessName="Process(3164)"/>
When parsed, the EventName attribute would be truncated to just "Enter" instead of the full value.
Solution
Applied proper XML escaping to EventName using the existing XmlUtilities.XmlEscape() method, which was already being used for ProcessName and DisplayFields but was missing for EventName.
Changes made:
- Line 291: Added
XmlUtilities.XmlEscape()to_event.EventName - Line 302: Added proper spacing for column attributes
- Line 318: Fixed typo in Rest field escaping (
"e;→")
After Fix
The same EventName now generates valid XML:
<Event EventName="Enter" providername="Microsoft-Azure-Devices" TimeMsec="783264.803" ProcessName="Process(3164)"/>
When parsed, the full EventName value is correctly preserved: Enter" providername="Microsoft-Azure-Devices
Testing
Verified that:
- EventName values with quotes, angle brackets, ampersands, and apostrophes are properly escaped
- XML documents are valid and parseable
- Original data is preserved through XML round-trip parsing
- No existing functionality is broken (minimal 3-line change)
Fixes #927.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot, can you please add a regression test for this to the PerfView.Tests project.
@copilot, can you please add a regression test for this to the
PerfView.Testsproject.
I've added comprehensive regression tests for the XML escaping fix in commit e9c0c28.
The new EventViewerTests.cs file includes:
- Tests for the exact issue #927 scenario with EventName containing quotes
- Parameterized tests for all XML special characters (&, ", ', <, >)
- Tests demonstrating the old broken behavior vs. new fixed behavior
- Verification that XML is valid and original data is preserved through round-trip parsing
The tests specifically cover the case where EventName="Enter\" providername=\"Microsoft-Azure-Devices" was being parsed incorrectly, and confirm that the fix properly escapes it to generate valid XML while preserving the full original value.
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.