EmailTextField renders a pattern attribute that browsers reject as an invalid regular expression

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

メンテナーはふだん 1 日以内に返信

@reiern70 がすでに取り組んでいます。

2026年11月12日 から。

  • #1887 @reiern70 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, javascript
領域
backend, frontend

調査の方向性

Start in EmailAddressValidator, where the pattern string with unescaped hyphens in its character classes lives, and in AbstractTextComponent#onComponentTag, which copies the pattern into the pattern attribute. Check open pull request #1887 first, since it already targets this fix. Done means the rendered pattern compiles with the v flag in the browser and the existing email validation tests still pass.

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

説明

Affects: 11.0.0; also current master (a7a4a4018d).
Component: wicket-core, AbstractTextComponent, EmailAddressValidator

What happens

A page with an EmailTextField renders:

<input type="email" ... pattern="^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*((\.[A-Za-z]{2,}){1}$)">

Chrome logs this error on the page, and again on each form submit:

Pattern attribute value ^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@... is not a valid regular expression:
Uncaught SyntaxError: Invalid regular expression: /^[_A-Za-z0-9-]+(...)$/v: Invalid character class

The browser then ignores the pattern attribute. The field still works, because type="email" makes the browser check the address, and EmailAddressValidator checks it again on the server. The result is console noise on every page with an email field, plus a pattern attribute that does nothing.

Cause

AbstractTextComponent#onComponentTag copies the Java regular expression of every PatternValidator into the HTML pattern attribute (tag.put("pattern", ((PatternValidator)validator).getPattern().toString())).

The HTML standard compiles pattern with the v flag (unicodeSets mode), and current browsers follow it. In v mode, a - that is not escaped inside a character class is a syntax error. That makes [_A-Za-z0-9-] invalid there, although Java accepts it.

Fix proposed

Escape the hyphens in EmailAddressValidator. The pattern below is valid in Java, and valid in the browser in v mode. It matches the same addresses (checked in Java and in Node with new RegExp(..., "v")):

"^[_A-Za-z0-9\\-]+(\\.[_A-Za-z0-9\\-]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*((\\.[A-Za-z]{2,}){1}$)"

Two broader options:

  • Note in the javadoc of PatternValidator that its pattern is sent to the browser, and must also be valid as a JavaScript regular expression in v mode.
  • Let an application keep a PatternValidator on the server without the attribute, for patterns that Java and JavaScript do not share.

Workaround

Add a behavior to the field after the validator, which removes the attribute:

email.add(new Behavior() {
    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
        tag.remove("pattern");
    }
});
主要言語
Java
スター
800
フォーク
437
平均マージ
21時間 36分
マージ済み PR(30日)
167

環境構築

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

はじめの一歩

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

apache/wicket のほかの issue

apache/wicket の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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