Keep XML-illegal characters from failing JSON responses (fixes #566) #575
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
mgaffigan
Fixes #566.
Problem
ObjectJSONSerializerconverts 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 inJsonXmlUtil.xmlToJsonrejects those references, so one code template with such a character in its code failsGET /api/codeTemplatesas JSON for the whole list: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
\uXXXXescape.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
ObjectJSONSerializerTestcases:Both fail on
mainwith the parse error above.:server:testis green.I haven't changed or tested the reverse direction, JSON → XML when saving through the JSON API.