Ensures that null values aren't used to create a CompositeStringStringKey#19646
Merged
nikolajlauridsen merged 1 commit intov13/devfrom Jul 1, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that null culture or segment values are replaced with string.Empty when instantiating CompositeStringStringKey, preventing constructor exceptions.
- Default null culture and segment to empty strings in key creation.
- Prevents runtime errors by sanitizing inputs before passing to the key constructor.
Comments suppressed due to low confidence (2)
src/Umbraco.PublishedCache.NuCache/Property.cs:243
- [nitpick] The variable name
kis ambiguous. Consider renaming it tocompositeKeyorcacheKeyfor clarity.
var k = new CompositeStringStringKey(culture ?? string.Empty, segment ?? string.Empty); // Null values are not valid when creating a CompositeStringStringKey.
src/Umbraco.PublishedCache.NuCache/Property.cs:243
- This behavior change isn’t covered by existing tests. Adding a unit test that passes null values for
cultureandsegmentwould ensure this guard remains effective.
var k = new CompositeStringStringKey(culture ?? string.Empty, segment ?? string.Empty); // Null values are not valid when creating a CompositeStringStringKey.
This was referenced Dec 9, 2025
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.
Prerequisites
Resolves: #19609
Description
I haven't been able to replicate the problem, which looks from the reported issue that it bubbles up from Commerce. But it does look to be similar to the fix applied for #16753 in #17024, and this is a further case.
The problem is that the constructor of
CompositeStringStringKeyaccepts null values but throws if they are passed. So we ned to make sure we usestring.Emptyas we did in the other case.Testing
Visual inspection will need to suffice here I believe.