Repository navigation
feat(xml): validate XML names and namespace prefixes - #12673
Debojyoti De Majumder (debojyoti10CC) wants to merge 2 commits into
Conversation
Report invalid-xml-name for @Xml.name and invalid-xml-prefix for @Xml.ns prefixes that are not valid XML Name/NCName. Signed-off-by: debojyoti10CC <[email protected]>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The enum-derived prefix validation branch lacks regression coverage for the diagnostic and unset namespace state, and the changelog incorrectly labels the bug fix as a feature.
2 open issues
What changed in this PR
This PR addresses #12663 by validating XML names and namespace prefixes in @typespec/xml, preventing invalid decorator values from reaching emitters. Direct @encodedName usage remains outside its scope.
Changes:
- Adds Unicode-aware XML
NameandNCNamevalidation. - Reports diagnostics and skips storing invalid names or prefixes.
- Adds decorator validation tests and a changelog entry.
| File | Description |
|---|---|
packages/xml/test/decorators.test.ts |
Adds valid and invalid name and prefix tests. |
packages/xml/src/xml-name.ts |
Implements XML Name and NCName validators. |
packages/xml/src/lib.ts |
Defines the two validation diagnostics. |
packages/xml/src/decorators.ts |
Validates values before storing XML metadata. |
.chronus/changes/xml-validate-names-2026-11-29-0-0-0.md |
Documents the new validation behavior. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Fixing it this way I don't think is the correct approach. @name is just a wrapper aronnd @encodedName where this can still reproduce. This also is possible to do as the original name so I think this needs a bit more design on what should happen.
|
Thanks, that makes sense. Checking only in |


Fixes #12663
@Xml.nameand the prefix given to@Xml.nsaccepted any string, so values that can never be valid XML ("1abc","a b","a<b", ...) reached emitters.This adds two diagnostics to
@typespec/xml:invalid-xml-name:@Xml.namevalue must match the XML 1.0Nameproduction (Unicode ranges per the spec). The encoded name is not set when invalid.invalid-xml-prefix: the@Xml.nsprefix must be a validNCName(no colon).Not covered: a raw
@encodedName("application/xml", ...)goes through the compiler decorator, so it is not validated here. Happy to discuss whether that belongs in the compiler.Testing: added cases in
packages/xml/test/decorators.test.ts(valid names incl. Unicode, invalid start chars / punctuation / whitespace, invalid and valid prefixes).pnpm vitest runin packages/xml: 42 passed; oxlint and prettier clean. Added a chronus change file.AI drafted the implementation and tests; I reviewed both and ran the package tests.