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

Abierto
#1,884 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@reiern70 ya está trabajando en esto.

Desde el 12/11/2026.

  • #1887 de @reiern70 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java, javascript
Área
backend, frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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");
    }
});
Lenguaje dominante
Java
Estrellas
800
Forks
437
Merge medio
21 h 36 min
PR fusionados (30 d)
167

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/wicket

Todos los issues de apache/wicket

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.