Skip to content

MetadataBindingUtils does not respect ODataUriResolver.EnableCaseInsensitive #3178

Open
@wertzui

Description

@wertzui

When checking if a provided string is a valid enum member, the method SingleValue always uses StringComparison.Ordinal in Line 67 instead of looking at ODataUriResolver.EnableCaseInsensitive and using a case insensitive comparison if it is true.

if (constantNode != null && constantNode.Value != null && (source.TypeReference.IsString() || source.TypeReference.IsIntegral()) && targetTypeReference.IsEnum())
{
string memberName = constantNode.Value.ToString();
IEdmEnumType enumType = targetTypeReference.Definition as IEdmEnumType;
if (enumType.ContainsMember(memberName, StringComparison.Ordinal))
{
string literalText = ODataUriUtils.ConvertToUriLiteral(constantNode.Value, default(ODataVersion));
return new ConstantNode(new ODataEnumValue(memberName, enumType.ToString()), literalText, targetTypeReference);
}
// If the member name is an integral value, we should try to convert it to the enum member name and find the enum member with the matching integral value
if (long.TryParse(memberName, out long memberIntegralValue) && enumType.TryParse(memberIntegralValue, out IEdmEnumMember enumMember))
{
string literalText = ODataUriUtils.ConvertToUriLiteral(enumMember.Name, default(ODataVersion));
return new ConstantNode(new ODataEnumValue(enumMember.Name, enumType.ToString()), literalText, targetTypeReference);
}
throw new ODataException(Error.Format(SRResources.Binder_IsNotValidEnumConstant, memberName));
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions