Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

HtmlInput changeType new instance causes side effects

Đang mở
#718 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
JavaScript
Star
952
Fork
183
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của HtmlUnit/htmlunit

Tất cả issue của HtmlUnit/htmlunit

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.