Repository navigation
[patch] Stop [PrefixAndSuffix] letting the prefix and suffix overlap, and reject empty strings - #408
Merged
Merged
Conversation
… and reject empty strings
PrefixAndSuffixAttribute checked StartsWith and EndsWith independently, so
one '"' satisfied [PrefixAndSuffix("\"", "\"")], and it returned success for
an empty string. A value now needs at least prefix.Length + suffix.Length
characters, and an empty string fails as it does for [StartsWith]/[EndsWith].
Fixes #338
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoEzLXruuTHCcJnXtVa49Z
|
This was referenced Oct 9, 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.



Fixes #338
What was wrong
PrefixAndSuffixAttributehad two problems:StartsWith(prefix)andEndsWith(suffix)independently, so the same characters could count as both. A lone"passed[PrefixAndSuffix("\"", "\"")], and"aba"passed[PrefixAndSuffix("ab", "ba")].[StartsWith]and[EndsWith], which reject one.Change (
Semantics.Strings/Validation/Attributes/Text/PrefixAndSuffixAttribute.cs)prefix.Length + suffix.Lengthfails before the prefix and suffix checks, so each delimiter needs its own characters.Release note: this tightens validation. A type that relied on
""or an overlapping value being accepted will now get anArgumentExceptionfromCreate.Tests (
TextValidationAttributesTests)PrefixAndSuffixAttribute_LoneDelimiterServingAsBoth_ShouldThrow:"with[PrefixAndSuffix("\"", "\"")]PrefixAndSuffixAttribute_OverlappingPrefixAndSuffix_ShouldThrow:abawith[PrefixAndSuffix("ab", "ba")]PrefixAndSuffixAttribute_EmptyString_ShouldThrowPrefixAndSuffixAttribute_DelimitersEachPresent_ShouldPass:""(two quotes) and"quoted"are still acceptedPrefixAndSuffixAttribute_AdjacentPrefixAndSuffix_ShouldPass:abbais accepted, since the prefix and suffix touch but don't overlapThese are the three inputs from the issue's acceptance criteria. The existing
PrefixAndSuffix_*tests, including"PrefixTestSuffix", still pass.Verification
PrefixAndSuffixtests pass.Semantics.Testsuite passes on net10.0: 1486 passed, 0 failed, 8 skipped (the same 8 are skipped onmain).Semantics.Stringsbuilds with the local Sonar analyzers (.sonarlint/sonar-local.props) with 0 warnings.🤖 Generated with Claude Code
https://claude.ai/code/session_01LoEzLXruuTHCcJnXtVa49Z
Generated by Claude Code