perfview icon indicating copy to clipboard operation
perfview copied to clipboard

Fix XML escaping for EventName when saving to XML

Open Copilot opened this issue 6 months ago • 4 comments

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:

  1. Line 291: Added XmlUtilities.XmlEscape() to _event.EventName
  2. Line 302: Added proper spacing for column attributes
  3. Line 318: Fixed typo in Rest field escaping (&quote;&quot;)

After Fix

The same EventName now generates valid XML:

<Event EventName="Enter&quot; providername=&quot;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 avatar Jun 02 '25 16:06 Copilot

@copilot, can you please add a regression test for this to the PerfView.Tests project.

brianrob avatar Jun 02 '25 17:06 brianrob

@copilot, can you please add a regression test for this to the PerfView.Tests project.

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.

Copilot avatar Jun 02 '25 17:06 Copilot

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Copilot avatar Jun 02 '25 17:06 Copilot

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Copilot avatar Jun 02 '25 18:06 Copilot