HtmlInput changeType new instance causes side effects
还没有人认领这个 Issue。
评估
调研方向
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 小时
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
HtmlUnit/htmlunit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 45/100
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 45/100
查看 HtmlUnit/htmlunit 的全部 Issue
相似的 Issue
-
bug 優先: 低
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
admission-deferred priority: medium status: ready work-class: scoped
难度 2/5 1-3 小时 新手友好度 70/100
melodic-software/claude-code-plugins#10887 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 1/5 1-3 小时 新手友好度 91/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复