[ 
https://issues.apache.org/jira/browse/FINERACT-2987?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sonigra Bhavya Hemendrabhai resolved FINERACT-2987.
---------------------------------------------------
    Resolution: Fixed

> DataValidatorBuilder.isOneOfTheseStringValues(Object... values) fails when 
> allowed values contain uppercase characters
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: FINERACT-2987
>                 URL: https://issues.apache.org/jira/browse/FINERACT-2987
>             Project: Apache Fineract
>          Issue Type: Bug
>          Components: System
>    Affects Versions: 1.16.0
>            Reporter: Sonigra Bhavya Hemendrabhai
>            Assignee: Sonigra Bhavya Hemendrabhai
>            Priority: Major
>              Labels: beginner, beginner-friendly
>             Fix For: 1.17.0
>
>
> In DataValidatorBuilder, the varargs overload `isOneOfTheseStringValues(final 
> Object... values)` checks whether the given value is in the allowed values 
> using:
>     final List<Object> rawValuesList = Arrays.asList(values);
>     if (this.value == null || 
> !rawValuesList.contains(this.value.toString().toLowerCase()))
> Notice that `this.value` is converted to lower-case, but `rawValuesList` is 
> not converted to lower-case. As a result, if the allowed values contain 
> uppercase or mixed-case characters (for example, "ACTIVE", "INACTIVE" or enum 
> names), `rawValuesList.contains(this.value.toString().toLowerCase())` will 
> compare "ACTIVE" with "active" via case-sensitive equals, which returns 
> false. The validation will always fail, even when the user passes the exact 
> matching string.
> In contrast, the sibling overload `isOneOfTheseStringValues(final 
> List<String> valuesList)` correctly lowercases the allowed list:
>     List<String> valuesListLowercase = 
> valuesList.stream().map(String::toLowerCase).toList();
> Steps to reproduce:
> Execute:
>     new 
> DataValidatorBuilder(errors).resource("test").parameter("action").value("ACTIVE")
>             .isOneOfTheseStringValues("ACTIVE", "INACTIVE");
> Result:
> Validation fails with error "The parameter `action` must be one of [ ACTIVE, 
> INACTIVE ] ."
> Expected:
> Validation should pass case-insensitively, consistent with 
> `isOneOfTheseStringValues(List<String>)`.
> Fix:
> The `Object... values` overload should delegate to 
> `isOneOfTheseStringValues(List<String>)`:
>     public DataValidatorBuilder isOneOfTheseStringValues(final Object... 
> values) {
>         return 
> isOneOfTheseStringValues(Arrays.stream(values).map(Object::toString).toList());
>     }



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to