SyntaxValidator rejects <?xml-stylesheet?> at the start and PIs with a tab/newline after the target
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
Research direction
Start with XmlDeclarationValidator.validate and SyntaxValidator._readPI, then find the existing tests for XML declarations and processing instructions. Add regression cases for the two PI forms described and verify both validate successfully, including targets separated from PI data by spaces, tabs, CR, or LF.
Written by the indexing model from the issue text.
Description
SyntaxValidator (fast-xml-validator 1.4.4, master c19b98a) rejects two kinds of well-formed XML that contain processing instructions.
1. A document that starts with a PI whose name begins with xml (e.g. xml-stylesheet) is read as an XML declaration
import { SyntaxValidator } from 'fast-xml-validator';
SyntaxValidator.validate(`<?xml-stylesheet type="text/xsl" href="feed.xsl"?><rss/>`);
// throws: XML declaration contains unknown attribute "type". Allowed: version, encoding, standalone.
SyntaxValidator.validate(`<?xmlfoo?><r/>`);
// throws: XML declaration contains invalid content: "foo".
Expected: both are valid (libxml2 / expat accept them). The same PI after a real <?xml version="1.0"?> line already validates, so this only hits feeds and SVGs that have no declaration.
Cause: XmlDeclarationValidator.validate uses xmlData.startsWith('<?xml'). The declaration is '<?xml' VersionInfo ... and VersionInfo starts with whitespace, so the next character has to be whitespace (or ? for the existing <?xml?> error path), e.g.
const hasDecl = xmlData.startsWith('<?xml') && (isWhiteSpace(xmlData[5]) || xmlData[5] === '?');
2. Tab, CR or LF after the PI target is taken as part of the target
SyntaxValidator.validate('<?pi\tdata?><r/>');
// throws: Processing instruction target "pi data" is not a valid XML Name.
SyntaxValidator.validate('<r><?xml-stylesheet\n href="a.xsl"?></r>');
// throws: Processing instruction target "xml-stylesheet\n" is not a valid XML Name.
Expected: valid. PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' and S is space, tab, CR or LF.
Cause: SyntaxValidator._readPI ends the target only on ' ' or '?':
if (!nameValidated && (ch === ' ' || ch === '?')) {
Using isWhiteSpace(ch) || ch === '?' (already imported from util.js) fixes it.
I checked both against expat on the inputs above. Happy to send a PR with specs if you want one.
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Extended search drops any query term that contains a line breakPossibly taken @goranai claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day