Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

HtmlInput changeType new instance causes side effects

オープン
#718 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
JavaScript
スター
952
フォーク
183
平均マージ
2日 1時間
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

HtmlUnit/htmlunit のほかの issue

HtmlUnit/htmlunit の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。