You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you have a short repro for this? "Short".Truncate(100, null) doesn't even compile for me, as the overloads are ambiguous. "Short".Truncate(100) correctly returns "Short". There are actually test cases for a case when the input string is shorter than the length.
In FixedLengthTruncator.cs, you correctly check if (value.Length > length) in most cases. However, this check is missing when truncationString == null. In that case, you call value.Substring(0, length), which can fail if value is shorter than the specified length.
"Short".Truncate(100, null); will throw exception:
In the Truncate method this code casues error, because value is shorter than lenght and thus value.Substring(0, legth) throws exception
https://github.com/Humanizr/Humanizer/blob/main/src/Humanizer/Truncation/FixedLengthTruncator.cs , line 21-26
if (truncationString == null || truncationString.Length > length)
{
return truncateFrom == TruncateFrom.Right
? value.Substring(0, length)
: value.Substring(value.Length - length);
}
The text was updated successfully, but these errors were encountered: