SyntaxValidator rejects <?xml-stylesheet?> at the start and PIs with a tab/newline after the target

Abierto Apto para principiantes
#23 1 comentario 0 reacciones 0 asignados Ver en GitHub

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
Área
backend, testing

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.