All contributions

FluentValidation/FluentValidation

FluentValidation

A popular .NET library for writing strongly typed validation rules in a fluent style, such as RuleFor(...).InclusiveBetween(...).

Language
C#
GitHub stars
9,780
Merged changes
1
Project site
fluentvalidation.net

What we changed

InclusiveBetween and ExclusiveBetween reject an inverted range even when the comparer returns any negative number, not only -1, for example for char bounds.

What this work shows

  • The IComparer<T> contract in .NET
  • Constructor argument validation
  • Unit tests in xUnit
What was broken

An inverted range was accepted silently

The RangeValidator constructor rejected a range from larger to smaller only when the comparison returned exactly -1. char.CompareTo returns the difference, so InclusiveBetween('c', 'a') was accepted and produced a rule that can never pass.

How we fixed it

Checking the sign instead of -1

The check now tests whether the result is below zero, as the IComparer<T> contract says. We added char bound tests for InclusiveBetween and ExclusiveBetween that failed before the change.

#2370

Merged change 1

  1. #2370 fix: reject an inverted range when the comparer returns a negative other than -1 Merged 9 September 2026

What it taught us

The .NET comparison contract only promises the sign of the result. Code that checks for exactly -1 works until the first comparer that returns -2, and we can find such spots and cover them with a test.

More about this technology: C# and .NET

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.