Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

HtmlInput changeType new instance causes side effects

Abierto
#718 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java
Área
backend

Línea de trabajo

Start by tracing how HtmlInput.setAttribute handles changes to type and how the replacement instance is attached to its page. Use the two testInput examples in the issue as regression cases, checking the serialized page output with page.asXml(). Done means setting type and then name preserves both attributes whether the input is appended before or after the type change.

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

Descripción

In one of the previous versions a breaking change with HtmlInput.setAttribute was introduced.
Currently, when changing type of HtmlInput a new instance is created and the instance worked on is no longer attached.
Looks like this behavior is intended but causes undesired side effects as the user has absolutely no way knowing they are working on a stale object.

(HtmlElementBuilder is a helper class we created, it basically just creates a StringWebResponse and passes it to to PageCreator)

Example 1 :

@Test
public void testInput() {
        HtmlPage page = HtmlElementBuilder.createPageFromString("<html><head></head><body></body></html>");
        HtmlElement input = (HtmlElement) page.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "test");
        page.getBody().appendChild(input);

        System.out.println(page.asXml());
}

Which result in this result:

<?xml version="1.0" encoding="UTF-8"?>
<html>
 <head/>
 <body>
   <input type="hidden"/>
 </body>
</html>

Another case:

@Test
public void testInput() {
        HtmlPage page = HtmlElementBuilder.createPageFromString("<html><head></head><body></body></html>");
        HtmlElement input = (HtmlElement) page.createElement("input");
        page.getBody().appendChild(input);
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "test");

        System.out.println(page.asXml());
    }

Results in:

<?xml version="1.0" encoding="UTF-8"?>
<html>
  <head/>
  <body>
    <input type="hidden"/>
  </body>
</html>

There are workarounds for this but this feels very error prone.

Lenguaje dominante
JavaScript
Estrellas
952
Forks
183
Merge medio
2 d 1 h
PR fusionados (30 d)
1

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 HtmlUnit/htmlunit

Todos los issues de HtmlUnit/htmlunit

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.