[
http://opensource.atlassian.com/projects/hibernate/browse/HV-435?page=com...
]
Hardy Ferentschik commented on HV-435:
--------------------------------------
It is a border case. The reasoning behind the {{URL}} constraint implementation was that
you can always use constraint composition ({{@NotNull}}, {{@NotEmpty}}, {{@URL}}). The BV
spec in fact favors constraint composition (hence the recommendation to generally return
{{true}} for {{null}}). Obviously the same argument could be made for {{@Pattern}}.
The difference, however, is that {{@Pattern}} is part of the spec and the documentation
does not mention the empty string as an exceptional case (only {{null}}). {{@URL}} is a
Hibernate Validator specific constraint and we are more flexible to change the behavior.
For a pattern an empty string seems also a valid input, since pattern can easily match the
empty string.
org.hibernate.validator.constraints.impl.PatternValidator rejecting
empty strings
---------------------------------------------------------------------------------
Key: HV-435
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-435
Project: Hibernate Validator
Issue Type: Bug
Components: validators
Affects Versions: 4.1.0.Final
Environment: Hibernate Core 3.5.6 with MySql database (not relevant to this bug)
Reporter: Stephen Hiley
Original Estimate: 1h
Remaining Estimate: 1h
The PatternValidator currently checks for a null value and returns true from isValid() in
that case. An empty string should have the same effect. This is necessary for the same
reason: to allow for an empty form submission (which commonly are submitted as empty
strings rather than nulls) and only validate when some value is submitted. IMO, this
should be standard behavior. If nothing else, provide an option to treat empty strings as
ignored in the same manner that null values are treated today.
Suggested modification:
public boolean isValid(String value, ConstraintValidatorContext
constraintValidatorContext) {
if ( value == null || value.length() == 0) {
return true;
}
Thanks,
Stephen Hiley
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira