Repository navigation
fix!: reject an empty needle in the params overloads of StartsWith and EndsWith - #1076
Merged
Merged
Conversation
…` and `EndsWith` #1069 rejected a `null` or empty argument for `Contains`, `StartsWith` and `EndsWith`, but only on the overloads taking an `IEnumerable<TItem>`: their `params` twins kept a null-only guard, so `EndsWith(emptyCollection)` threw while `EndsWith()` asserted nothing at all and passed for any subject. That left one expectation contradicting itself depending on which overload the caller happened to bind to, which is the worst version of the inconsistency to ship in a major. All 28 `params` overloads across `StartsWith`, `EndsWith`, `DoesNotStartWith` and `DoesNotEndWith` now use the same `ThrowIfNullOrEmpty` guard as their siblings, so the exception type and the message no longer depend on the overload either. The eight redundant `ArgumentNullException.ThrowIfNull` calls sitting directly after `ThrowIfNullOrEmpty` on the asynchronous non-`params` overloads have been dropped as dead, and `using System;` with them. Several `WhenSubjectIsNull_ShouldFail` tests reached the null subject through an empty needle, so they were asserting the subject's behaviour by way of the argument that now throws; they were given a real needle rather than a suppression, and the tests that pinned the old empty-needle behaviour now pin the exception. The argument-null tests asserted only a parameter name, which is why the differing message went unnoticed, so they pin the message now too.
vbreuss
force-pushed
the
fix/startswith-endswith-params-validation
branch
from
September 13, 2026 14:12
c12a91c to
ddaf2f3
Compare
Contributor
🚀 Benchmark ResultsDetails
|
Contributor
Test Results 23 files - 27 23 suites - 27 10m 9s ⏱️ + 1m 41s Results for commit ddaf2f3. ± Comparison against base commit 9547e82. This pull request removes 3257 and adds 3224 tests. Note that renamed tests count towards both. |
Contributor
👽 Mutation ResultsaweXpectDetails
The final mutation score is 88.86%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0 |
|
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…rams` overloads of `StartsWith` and `EndsWith` (#1076) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…rams` overloads of `StartsWith` and `EndsWith` (#1076) by Valentin Breuß
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



#1069 rejected a
nullor empty argument forContains,StartsWithandEndsWith, but only on the overloads taking anIEnumerable<TItem>: theirparamstwins kept a null-only guard, soEndsWith(emptyCollection)threw whileEndsWith()asserted nothing at all and passed for any subject. That left one expectation contradicting itself depending on which overload the caller happened to bind to, which is the worst version of the inconsistency to ship in a major.All 28
paramsoverloads acrossStartsWith,EndsWith,DoesNotStartWithandDoesNotEndWithnow use the sameThrowIfNullOrEmptyguard as their siblings, so the exception type and the message no longer depend on the overload either. The eight redundantArgumentNullException.ThrowIfNullcalls sitting directly afterThrowIfNullOrEmptyon the asynchronous non-paramsoverloads have been dropped as dead, andusing System;with them.Several
WhenSubjectIsNull_ShouldFailtests reached the null subject through an empty needle, so they were asserting the subject's behaviour by way of the argument that now throws; they were given a real needle rather than a suppression, and the tests that pinned the old empty-needle behaviour now pin the exception. The argument-null tests asserted only a parameter name, which is why the differing message went unnoticed, so they pin the message now too.