Describe the bug
Context
- Go's nightly build pipeline failed with this test
XMLModelWithTextValue_Put.
- The root cause is Go's
encoding/xml encodes \n in xml as 
, The dev version of @typespec/spec-api (0.1.0-dev.3) switched its XML parser from xml2js to fast-xml-parser in 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
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
Describe the bug
Context
XMLModelWithTextValue_Put.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
processEntities: true,htmlEntities: true, andtrimValues: falseto support
characters. https://github.com/microsoft/typespec/blob/main/packages/spec-api/src/request-validations.ts#L67Reproduction
Expected output:
Checklist