SyntaxValidator rejects <?xml-stylesheet?> at the start and PIs with a tab/newline after the target
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 88/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, node.js
Línea de trabajo
Empieza con XmlDeclarationValidator.validate y SyntaxValidator._readPI; después, busca las pruebas existentes para las declaraciones XML y las instrucciones de procesamiento. Añade casos de regresión para las dos formas de PI descritas y verifica que ambas se validen correctamente, incluso cuando los targets están separados de los datos de PI por espacios, tabulaciones, CR o LF.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- JavaScript
- Estrellas
- 3
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
-
Extended search drops any query term that contains a line breakPosiblemente ocupada @goranai la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
0.3.14: pdfmake.virtualfs renamed to sharedVirtualfs without changelog entry (breaking change)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día