Skip to content

Add Xml.Escape helper method - #85

Merged
Tyrrrz merged 8 commits into
primefrom
copilot/add-helper-method-xml-escape
Jul 11, 2026
Merged

Add Xml.Escape helper method#85
Tyrrrz merged 8 commits into
primefrom
copilot/add-helper-method-xml-escape

Conversation

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Adds a static Xml.Escape(string str) helper for producing valid XML text from arbitrary strings.

Changes

  • PowerKit/Xml.cs — new Xml static class with Escape(string str):
    • Replaces the five XML special characters with their entities (&, <, >, ", ')
    • Removes characters illegal in XML 1.0 (control chars outside #x9/#xA/#xD, isolated surrogates, U+FFFE/U+FFFF)
    • Preserves valid supplementary characters (well-formed surrogate pairs)
    • Allocation-free fast path when the input requires no changes
  • PowerKit.Tests/XmlTests.cs — tests covering each special character, control char removal, surrogate pair preservation, isolated surrogate removal, empty string, and null input

Example

Xml.Escape("1 < 2 & \"foo\" = 'bar'")
// → "1 &lt; 2 &amp; &quot;foo&quot; = &apos;bar&apos;"

Xml.Escape("foo\u0001bar")  // U+0001 is illegal in XML 1.0
// → "foobar"

@Tyrrrz Tyrrrz added the enhancement New feature or request label Jul 11, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 11, 2026 13:50
Copilot AI review requested due to automatic review settings July 11, 2026 13:50
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.45%. Comparing base (ffbc21c) to head (2d8f6a7).

Files with missing lines Patch % Lines
PowerKit/Xml.cs 89.74% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #85      +/-   ##
==========================================
+ Coverage   85.31%   85.45%   +0.14%     
==========================================
  Files          70       71       +1     
  Lines        1137     1176      +39     
  Branches      202      218      +16     
==========================================
+ Hits          970     1005      +35     
  Misses        121      121              
- Partials       46       50       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a small XML escaping utility to the PowerKit library (Xml.Escape(string)) to produce XML-safe text content by entity-escaping the five XML special characters and removing XML 1.0–illegal characters, with a no-allocation “no changes needed” fast path. Includes a focused test suite validating special-character escaping, invalid character removal, and surrogate handling.

Changes:

  • Add PowerKit.Xml.Escape(string) to escape & < > " ' and remove XML 1.0–illegal characters (including isolated surrogates).
  • Preserve valid supplementary characters via well-formed surrogate pairs.
  • Add unit tests covering special chars, whitespace, control char removal, surrogate pairs, isolated surrogates, empty, and null.

Reviewed changes

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

File Description
PowerKit/Xml.cs Introduces Xml.Escape(string) with XML 1.0 character validity filtering and entity escaping.
PowerKit.Tests/XmlTests.cs Adds unit tests validating escaping/removal rules and surrogate behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit.Tests/XmlTests.cs
Copilot AI requested a review from Tyrrrz July 11, 2026 13:57
Comment thread PowerKit.Tests/XmlTests.cs Outdated
Copilot AI requested a review from Tyrrrz July 11, 2026 18:35
@Tyrrrz
Tyrrrz merged commit 96a1e2a into prime Jul 11, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-helper-method-xml-escape branch July 11, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants