System.Xml: XSD allows patterns that should be invalid

Abierto
#136,967 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp
Área
backend

Línea de trabajo

Start by tracing how System.Xml validates xs:pattern values and how its regex handling differs from the XML regex dialect described in the linked specification. The report provides two reproductions involving grouping and backreferences; use them to identify the relevant validation tests and confirm the expected schema errors. Done means those patterns are rejected while valid XML regex patterns continue to work.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area-System.Xml untriaged
Description

XSD schemas allows use of regex string that are not valid according to the XML regex dialect but are valid in .NET regex dialect. Some examples include:

  • Backtracking
  • Various grouping constructs
  • Look arounds
Reproduction Steps
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

Check("(?&lt;x&gt;y)", "<id>y</id>"); // '?' should not be allowed to follow '('. Instead this creates a named group.
Check("(y)\\2", "<id>yy</id>"); // "\\2" should be an invalid escape sequence. Instead this creates a back reference

static void Check(string pattern, string xml)
{
    string xsd = $@"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='id'>
    <xs:simpleType>
      <xs:restriction base='xs:string'>
        <xs:pattern value='{pattern}'/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>";

    var settings = new XmlReaderSettings
    {
        ValidationType = ValidationType.Schema
    };
    settings.Schemas.Add(null, XmlReader.Create(new StringReader(xsd)));

    int errors = 0;
    settings.ValidationEventHandler += (_, e) =>
    {
        if (e.Severity == XmlSeverityType.Error)
            errors++;
        else
            throw e.Exception;
    };

    using var reader = XmlReader.Create(new StringReader(xml), settings);
    while (reader.Read()) { }

    Console.WriteLine(
        $"{pattern,-12} {xml,-36} {(errors == 0 ? "VALID" : "INVALID")}");
}
Expected behavior

Exceptions or output INVALID for all three since the patterns are not valid according to xml spec?

Actual behavior

Both checks outputs VALID.

Regression?

Not what i can find

Known Workarounds

No response

Configuration

No response

Other information

System.Xml has contribution bar "". I would expect these issues to be classified as edge-cased and the bug report to closed as won't fix, but at least it is logged.

Lenguaje dominante
C#
Estrellas
18.4k
Forks
5.8k
Merge medio
2 d 14 h
PR fusionados (30 d)
585

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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.

Más de dotnet/runtime

Todos los issues de dotnet/runtime

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.