EmailTextField renders a pattern attribute that browsers reject as an invalid regular expression
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java, javascript
調査の方向性
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
PatternValidatorthat its pattern is sent to the browser, and must also be valid as a JavaScript regular expression invmode. - Let an application keep a
PatternValidatoron 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/wicket のほかの issue
-
PropertyResolver fails on JDK classes with a non-public field named like the property対応中かも @vaibhavgupta443 が今日担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
apache/wicket#1991 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Stop the autocomplete from accumulating request parameters while typing対応中かも @aryankalantri が今日担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
apache/wicket#1947 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Validate the report-uri value given to CSPHeaderConfiguration#reportBack対応中かも @AzizOuertani が 3 日前に担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
apache/wicket#1946 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
メンテナーはふだん 6 日以内に返信
-
account assessment course feature lecture
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
bug db/dameng user-priority/P2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
app:learninggoalhub enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100