A reversed PatternValidator renders a pattern attribute that rejects the input the validator accepts

未关闭
#1,886 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@reiern70 已经在做这个了。

开始于 2026年11月12日。

  • #1890 来自 @reiern70 —— 未关闭
  • #1892 来自 @reiern70 —— 未关闭
  • #1893 来自 @reiern70 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
html, java
领域
frontend

调研方向

The pattern attribute is written in AbstractTextComponent#onComponentTag and HTML5Attributes#onInput, both in wicket-core. Start by reading how those two places iterate over the PatternValidator instances, and add an isReverse() getter to PatternValidator. Done when a reversed validator no longer produces a pattern attribute in the rendered <input>, and the existing tests for HTML5 attributes still pass.

由索引模型根据 Issue 内容生成。

描述

Affects: 11.0.0 and current master, on every text component. 10.x when the HTML5Attributes behavior is added.
Component: wicket-core, AbstractTextComponent, HTML5Attributes, PatternValidator

What happens

A text field with a reversed PatternValidator:

field.add(new PatternValidator("[a-z]+").setReverse(true));

renders:

<input type="text" ... pattern="[a-z]+">

The validator means "input that matches [a-z]+ is invalid". The pattern attribute tells the browser the opposite: input that does not match is invalid. A non-empty value can't pass both checks:

  • 123 is valid on the server, but the browser blocks the submit (patternMismatch, checked in Chrome and Firefox).
  • abc passes the browser, and the server rejects it.

Only an empty value gets through, because neither check applies to it.

Cause

AbstractTextComponent#onComponentTag (and HTML5Attributes#onInput) copies the pattern of every PatternValidator into the pattern attribute and ignores the reverse flag. PatternValidator has no getter for that flag, so the renderers can't see it.

Fix proposed

Render no pattern attribute for a reversed validator, and leave the check to the server. An HTML pattern can't express "must not match" reliably for an arbitrary Java pattern. This needs a public getter, PatternValidator#isReverse().

Workaround

Remove the attribute with a behavior added after the validator:

field.add(new Behavior() {
    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
        tag.remove("pattern");
    }
});

Found while fixing #1884.

主要语言
Java
星标
800
派生
437
平均合并
21 小时 36 分钟
30 天内合并 PR
167

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/wicket 的其他 Issue

查看 apache/wicket 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。