[
https://issues.apache.org/jira/browse/WW-5703?focusedWorklogId=1041373&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1041373
]
ASF GitHub Bot logged work on WW-5703:
--------------------------------------
Author: ASF GitHub Bot
Created on: 14/Sep/26 11:18
Start Date: 14/Sep/26 11:18
Worklog Time Spent: 10m
Work Description: sonarqubecloud[bot] commented on PR #1938:
URL: https://github.com/apache/struts/pull/1938#issuecomment-5663107127
## [](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1938)
**Quality Gate passed**
Issues
 [1 New
issue](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1938&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1938&issueStatuses=ACCEPTED)
Measures
 [0 Security
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=1938&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1938&metric=new_coverage&view=list)
 [0.0% Duplication on New
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1938&metric=new_duplicated_lines_density&view=list)
<!
Issue Time Tracking
-------------------
Worklog Id: (was: 1041373)
Time Spent: 1h 10m (was: 1h)
> HTML5 pattern false-rejects whitespace-only input that the regex validator
> accepts
> ----------------------------------------------------------------------------------
>
> Key: WW-5703
> URL: https://issues.apache.org/jira/browse/WW-5703
> Project: Struts 2
> Issue Type: Bug
> Components: Core Tags
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 7.4.0
>
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> Found reviewing WW-5695 (PR #1865). Violates that feature's governing rule:
> emit a constraint only when the browser cannot reject input the server would
> accept.
> h3. What happens
> {{StrutsHtmlConstraintProvider.addPattern}} refuses to emit {{pattern}} when
> the regex validator has {{trim=true}}, because the server would then match
> the trimmed value while the browser matches the raw one. That guard is
> correct as far as it goes, but it is not the only trim in
> {{RegexFieldValidator}}. {{validateFieldValue}} opens with a blank check that
> runs _unconditionally_, regardless of the {{trim}} param:
> {code:java}
> protected void validateFieldValue(Object object, String value, String
> regexToUse) {
> // string must not be empty
> String str = value.trim();
> if (str.isEmpty()) {
> LOG.debug("Value is empty, please use a required validator");
> return;
> }
> ...
> {code}
> So the exact configuration in which {{pattern}} _is_ emitted -
> {{trim=false}}, case-sensitive, portable regex - is also the configuration in
> which the server silently accepts a whitespace-only value.
> h3. Reproduction
> A regex field-validator with {{regex}} of {{^\d{5}$}} and {{trim}} of
> {{false}}, on an {{s:textfield}} named {{zip}}, html5 theme,
> {{struts.ui.html5.constraints=true}}.
> The user types a single space.
> * Server: {{" ".trim().isEmpty()}} is true, the validator returns early, no
> field error is added, the action executes.
> * Browser: the value is non-empty so {{pattern}} applies, the match fails,
> and the submit is blocked with "Please match the requested format."
> The user cannot get past a field the server would have let through. HTML
> skips {{pattern}} for the empty string, but not for whitespace-only input, so
> there is no browser-side escape.
> h3. Possible closures
> * emit {{pattern}} only when the field also carries a {{requiredstring}}
> validator, which does reject blank server-side, so the two sides agree again;
> or
> * refuse to emit when the regex cannot itself match a whitespace-only string.
> h3. Test gap
> {{StrutsHtmlConstraintProviderTest.regexEmitsPatternWhenPortableAndCaseSensitive}}
> asserts only that the attribute is produced, so nothing currently catches
> this. A case pinning server-side acceptance of a whitespace-only value should
> land with the fix.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)