You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MaskXmlInvalidCharacters() corrupts supplementary Unicode characters in XmlLayoutSchemaLog4J #290
Summary
MaskXmlInvalidCharacters() in Transform.cs processes UTF-16 code units instead of Unicode code points. This causes supplementary characters (U+10000–U+10FFFF) encoded as surrogate pairs to be replaced with “?”, resulting in silent data corruption in XML log output.
Root Cause
The regex [^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD] operates on UTF-16 char units. Supplementary characters are represented as surrogate pairs, and both surrogates fall outside the allowed range, so both are replaced.
Impact
Silent corruption of non-BMP characters (emoji, CJK extensions, symbols)
Loss of original data in XmlLayoutSchemaLog4J XML output
Affects structured logs consumed by downstream systems
Example
Input: admin🔑
Output: admin?
Suggestion
Use code-point aware processing (surrogate pair handling or XmlConvert.IsXmlChar) instead of regex over UTF-16 code units.
Activity
preserve UTF-16 surrogate pairs in MaskXmlInvalidCharacters - fixes #290
FreeAndNil commentedon Apr 16, 2026
@N0tre3l thanks for reporting.
Can you check whether #291 fixes your problem?
N0tre3l commentedon Apr 16, 2026
Yes, #291 fixes it. The regex now matches surrogate pairs first and preserves them, only replacing lone surrogates and other invalid code units
preserve UTF-16 surrogate pairs in MaskXmlInvalidCharacters - fixes #290