Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Context
- Go's nightly build pipeline failed with this test
XMLModelWithTextValue_Put. - The root cause is Go's
encoding/xmlencodes\nin xml as
, The dev version of @typespec/spec-api (0.1.0-dev.3) switched its XML parser fromxml2jstofast-xml-parserin this pr. XMLParser() with default options leaves
as a literal string, so spector's comparison of the request body against the expected value fails.
Fix
- The XMLParser may need to add those config
processEntities: true,htmlEntities: true, andtrimValues: falseto support
characters. https://github.com/microsoft/typespec/blob/main/packages/spec-api/src/request-validations.ts#L67
Reproduction
// repro.mjs
// Demonstrates that fast-xml-parser does not decode 
 (numeric char ref for \n)
// by default, which causes Spector XML payload comparison to fail when the Go SDK
// encodes newlines in chardata fields as 
 (valid per XML spec, encoding/xml default).
import { XMLParser } from "fast-xml-parser";
// Go's encoding/xml serializes a chardata field containing "\n text\n"
// as the following wire XML:
const wireXml = "<root>
 This is some text.
</root>";
// Expected value (what the TypeSpec spec / Go test expects):
const expected = "\n This is some text.\n";
const defaultResult = new XMLParser().parse(wireXml).root;
const fixedResult = new XMLParser({ processEntities: true, htmlEntities: true, trimValues: false })
.parse(wireXml).root;
console.log("wire XML :", wireXml);
console.log("expected :", JSON.stringify(expected));
console.log("default :", JSON.stringify(defaultResult), defaultResult === expected ? "✅" : "❌ MISMATCH");
console.log("with fix :", JSON.stringify(fixedResult), fixedResult === expected ? "✅" : "❌ MISMATCH");Expected output:
wire XML : <root>
 This is some text.
</root>
expected : "\n This is some text.\n"
default : "
 This is some text.
" ❌ MISMATCH
with fix : "\n This is some text.\n" ✅
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
[-][spec-api]: XMLParser does not decode numeric XML character references (
) in chardata by default[/-][+][spec-api]: XMLParser does not decode `
` by default[/+]JiaqiZhang-Dev commentedon Apr 14, 2026
solved by removing new lines: https://github.com/Azure/autorest.go/pull/1917/changes