AddIfDirective.java mistakes processing instructions for elements
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
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
- 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.
Más de yegor256/xembly
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
let's use Xnav instead of `XPathFactory`Quizá libre de nuevo @volodya-lombrozo la tomó hace 635 días y no hay ningún pull request abierto. Abiertoenhancement
yegor256/xembly#246 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dependency DashboardPosiblemente ocupada @yegor256 la tomó hace 1 día. Abiertowontfix
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
yegor256/xembly#111 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de yegor256/xembly
Issues similares
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
commons-app/apps-android-commons#7341 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
NationalSecurityAgency/ghidra#10220 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día