← Back to Pull requests

Keep XML-illegal characters from failing JSON responses (fixes #566) #575

Open
unknown opened this pull request with 244 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 12, 2026 13:50 UTC
Author

Fixes #566.

Problem

ObjectJSONSerializer converts an object to XML with XStream, then parses that XML to build the JSON. XStream writes characters that XML 1.0 doesn't allow, such as U+FFFE, U+FFFF or a C0 control other than tab, LF or CR, as character references like . The XML parser in JsonXmlUtil.xmlToJson rejects those references, so one code template with such a character in its code fails GET /api/codeTemplates as JSON for the whole list:

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[...]
Message: Character reference "&#xfffe" is an invalid XML character.

The same path serves channels, global scripts and anything else with free text, so they were exposed too.

Fix

In ObjectJSONSerializer, before parsing:

1. Find each character reference to a code point that XML 1.0 doesn't allow (up to U+FFFF).
2. Replace it with a placeholder: a private-use character that doesn't occur anywhere in that document, followed by the four hex digits.
3. After the conversion, turn each placeholder into a JSON \uXXXX escape.

The characters come through unchanged instead of being stripped. Documents without such references take the same path as before. Legal character references are left alone.

This doesn't add the other option from the issue, rejecting such characters on save. That could still be useful, but it's a separate change.

Tests

Two new ObjectJSONSerializerTest cases:

  • A code template whose code contains U+FFFE, U+FFFF, U+0001, U+001F and U+0008 serializes, and the parsed JSON contains the code unchanged.

  • A channel description that contains U+E000–U+E002 and text that looks like a placeholder, next to a U+FFFE, comes back unchanged. This shows the placeholder can't collide with existing text.
  • Both fail on main with the parse error above. :server:test is green.

    I haven't changed or tested the reverse direction, JSON → XML when saving through the JSON API.

    Diff: 244 lines (+183 / -61) across 3 files Reviewer: mgaffigan Review duration: 26072m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 244 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.329
    Real PR Conversation Timeline
    1 comments
    "Review active on #575"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.8% (MEDIUM) · Higher = larger blast radius
    38.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.7% · Safe to merge
    20.7%