Skip to content

[spec-api]: XMLParser does not decode 
 by default #10350

Closed

Description

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>&#xA;  This is some text.&#xA;</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>&#xA;  This is some text.&#xA;</root>
expected  : "\n  This is some text.\n"
default   : "&#xA;  This is some text.&#xA;" ❌ MISMATCH
with fix  : "\n  This is some text.\n" ✅

Checklist

Activity

  1. changed the title [-][spec-api]: XMLParser does not decode numeric XML character references (&#xA;) in chardata by default[/-] [+][spec-api]: XMLParser does not decode `&#xA;` by default[/+] on Apr 13, 2026
  2. JiaqiZhang-Dev commented on Apr 14, 2026

    @JiaqiZhang-Dev
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions