Skip to content

Ensures that null values aren't used to create a CompositeStringStringKey#19646

Merged
nikolajlauridsen merged 1 commit intov13/devfrom
v13/bugfix/ensure-null-culture-segment-not-used-for-composite-string-key
Jul 1, 2025
Merged

Ensures that null values aren't used to create a CompositeStringStringKey#19646
nikolajlauridsen merged 1 commit intov13/devfrom
v13/bugfix/ensure-null-culture-segment-not-used-for-composite-string-key

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

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 CompositeStringStringKey accepts null values but throws if they are passed. So we ned to make sure we use string.Empty as we did in the other case.

Testing

Visual inspection will need to suffice here I believe.

Copilot AI review requested due to automatic review settings July 1, 2025 10:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 k is ambiguous. Consider renaming it to compositeKey or cacheKey for 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 culture and segment would ensure this guard remains effective.
        var k = new CompositeStringStringKey(culture ?? string.Empty, segment ?? string.Empty); // Null values are not valid when creating a CompositeStringStringKey.

Copy link
Copy Markdown
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants