reiern70 opened a new issue, #1886:
URL: https://github.com/apache/wicket/issues/1886

   **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`:
   
   ```java
   field.add(new PatternValidator("[a-z]+").setReverse(true));
   ```
   
   renders:
   
   ```html
   <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:
   
   ```java
   field.add(new Behavior() {
       @Override
       public void onComponentTag(Component component, ComponentTag tag) {
           tag.remove("pattern");
       }
   });
   ```
   
   Found while fixing #1884.
   


-- 
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]

Reply via email to