reiern70 opened a new pull request, #1887: URL: https://github.com/apache/wicket/pull/1887
Closes #1884 `AbstractTextComponent`, like the `HTML5Attributes` behavior, renders the pattern of a `PatternValidator` into the HTML `pattern` attribute. Browsers compile that attribute as a JavaScript regular expression with the `v` flag, where a `-` left unescaped in a character class is a syntax error. The pattern of `EmailAddressValidator` has four such classes (`[_A-Za-z0-9-]`), so Chrome logged "Invalid regular expression" on every page with an `EmailTextField`, and again on each submit, and Chrome and Firefox both ignored the attribute. ### What it does now - The hyphens are escaped (`[_A-Za-z0-9\-]`). Java reads the pattern as before, and it matches the same addresses. - The class javadoc of `PatternValidator` says that its pattern is rendered for the browser and has to compile there with the `v` flag, and that compile flags such as `CASE_INSENSITIVE` are not rendered. ### What applications see The browser now enforces the pattern. It rejects an address such as `name@host` before the form is submitted, with its own message. Before, the request reached the server and failed `EmailAddressValidator` there. No API change, nothing to migrate. ### Not in this PR - A reversed `PatternValidator` renders a `pattern` attribute that contradicts it: #1886, fixed in #REVERSE, which is stacked on this branch. - An opt-out for applications whose Java pattern is not valid in JavaScript, the second broader option in #1884. ### Backport To `wicket-11.x` in #PR11, a clean cherry-pick. To `wicket-10.x` in #PR10, with the javadoc and the commit message adapted, because on 10.x only `HTML5Attributes` renders the attribute. ### Tests - `EmailValidatorTest` checks a hyphenated address as well. - The old and the new pattern, checked in Chrome and Firefox (`validity.patternMismatch`, console) and in Node with `new RegExp(..., "v")`: the old one does not compile and the browsers ignore it. The new one compiles, and it gives the same results as Java on the test addresses. - `mvn clean verify -Pjs-test` is green. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
