Efficient checks for empty strings and single character matches
Closes gh-25552 Closes gh-25553
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,7 +105,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
||||
public void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs,
|
||||
@Nullable String defaultMessage) {
|
||||
|
||||
if ("".equals(getNestedPath()) && !StringUtils.hasLength(field)) {
|
||||
if (!StringUtils.hasLength(getNestedPath()) && !StringUtils.hasLength(field)) {
|
||||
// We're at the top of the nested object hierarchy,
|
||||
// so the present level is not a field but rather the top object.
|
||||
// The best we can do is register a global error here...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -311,7 +311,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
|
||||
@Nullable
|
||||
protected Object getRejectedValue(String field, ConstraintViolation<Object> violation, BindingResult bindingResult) {
|
||||
Object invalidValue = violation.getInvalidValue();
|
||||
if (!"".equals(field) && !field.contains("[]") &&
|
||||
if (!field.isEmpty() && !field.contains("[]") &&
|
||||
(invalidValue == violation.getLeafBean() || field.contains("[") || field.contains("."))) {
|
||||
// Possibly a bean constraint with property path: retrieve the actual property value.
|
||||
// However, explicitly avoid this for "address[]" style paths that we can't handle.
|
||||
|
||||
Reference in New Issue
Block a user