AddIfDirective.java mistakes processing instructions for elements

Abierto
#440 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Inf1mum ya está trabajando en esto.

Desde el 14/11/2026.

  • #441 de @Inf1mum — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
tooling

Línea de trabajo

Start in src/main/java/org/xembly/AddIfDirective.java, lines 53-57, where the child scan compares getNodeName() without checking getNodeType(). Fix the match to require Node.ELEMENT_NODE and confirm the existing creation path then adds the missing element, as shown by AttrDirective.exec() casting the node to Element. Done means the snippet in src/test/java/org/xembly (add a regression case whose PI target equals the requested element name) yields <root><?item data?><item id="1"/></root>. Note pull request #441 is already open on this, so coordinate before starting.

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

Descripción

ADDIF 'item' reuses <?item data?> instead of creating an item element. A following ATTR then throws ClassCastException because its cursor contains a processing instruction.

For example:

new Xembler(
    new Directives()
        .add("root")
        .pi("item", "data")
        .addIf("item")
        .attr("id", "1")
).dom();

This should produce <root><?item data?><item id="1"/></root>. Instead, ADDIF leaves the element absent and Element.class.cast(node) in AttrDirective.exec() receives the processing instruction.

In src/main/java/org/xembly/AddIfDirective.java, lines 53–57, the lookup compares names without checking the node type:

if (kids.item(idx).getNodeName().equals(this.name.raw())) {
    target = kids.item(idx);
    break;
}

A processing instruction's node name is its target, so it can match any requested element name. Restrict the match to element nodes:

if (kids.item(idx).getNodeType() == Node.ELEMENT_NODE
    && kids.item(idx).getNodeName().equals(this.name.raw())) {
    target = kids.item(idx);
    break;
}

This lets the existing creation path add the missing element while preserving the processing instruction. Add a regression case with a PI whose target equals the requested element name; the existing PI coverage uses a different target.

Lenguaje dominante
Java
Estrellas
248
Forks
33
Merge medio
17 h 59 min
PR fusionados (30 d)
46

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.

Más de yegor256/xembly

Todos los issues de yegor256/xembly

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.