From 593f1eea6cd1d9059a0961461d52fb9a5a72ac64 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Date: Tue, 27 Feb 2024 09:56:57 +0100 Subject: [PATCH] V14: Align cultures & segments casing (#15745) * Removing to ToLowerInvariant from culture and segments * Adding ToLowerInvariant for DeliveryAPIIndex to not modify the stored data * Fix failing test - remove ToLowerInvariant --- .../Models/ContentCultureInfosCollection.cs | 2 -- src/Umbraco.Core/Models/Property.cs | 30 +++++++------------ .../DeliveryApiContentIndexValueSetBuilder.cs | 2 +- .../Services/ContentServiceTests.cs | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs b/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs index cf8a2f0328..b8748d6bbc 100644 --- a/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs +++ b/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs @@ -48,8 +48,6 @@ public class ContentCultureInfosCollection : ObservableDictionary /// Gets or sets the culture of the property. @@ -577,18 +575,14 @@ public class Property : EntityBase, IProperty /// The culture is either null (invariant) or a non-empty string. If the property is /// set with an empty or whitespace value, its value is converted to null. /// - public string? Culture - { - get => _culture; - set => _culture = value.IsNullOrWhiteSpace() ? null : value!.ToLowerInvariant(); - } + public string? Culture { get; set; } public object DeepClone() => Clone(); public bool Equals(PropertyValue? other) => other != null && - _culture == other._culture && - _segment == other._segment && + Culture == other.Culture && + Segment == other.Segment && EqualityComparer.Default.Equals(EditedValue, other.EditedValue) && EqualityComparer.Default.Equals(PublishedValue, other.PublishedValue); @@ -599,11 +593,7 @@ public class Property : EntityBase, IProperty /// The segment is either null (neutral) or a non-empty string. If the property is /// set with an empty or whitespace value, its value is converted to null. /// - public string? Segment - { - get => _segment; - set => _segment = value?.ToLowerInvariant(); - } + public string? Segment { get; set; } /// /// Gets or sets the edited value of the property. @@ -621,8 +611,8 @@ public class Property : EntityBase, IProperty public IPropertyValue Clone() => new PropertyValue { - _culture = _culture, - _segment = _segment, + Culture = Culture, + Segment = Segment, PublishedValue = PublishedValue, EditedValue = EditedValue, }; @@ -632,14 +622,14 @@ public class Property : EntityBase, IProperty public override int GetHashCode() { var hashCode = 1885328050; - if (_culture is not null) + if (Culture is not null) { - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(_culture); + hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(Culture); } - if (_segment is not null) + if (Segment is not null) { - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(_segment); + hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(Segment); } if (EditedValue is not null) diff --git a/src/Umbraco.Infrastructure/Examine/DeliveryApiContentIndexValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/DeliveryApiContentIndexValueSetBuilder.cs index e8226d994c..5c4811069f 100644 --- a/src/Umbraco.Infrastructure/Examine/DeliveryApiContentIndexValueSetBuilder.cs +++ b/src/Umbraco.Infrastructure/Examine/DeliveryApiContentIndexValueSetBuilder.cs @@ -76,7 +76,7 @@ internal sealed class DeliveryApiContentIndexValueSetBuilder : IDeliveryApiConte foreach (var culture in availableCultures) { - var indexCulture = culture ?? "none"; + var indexCulture = culture?.ToLowerInvariant() ?? "none"; var isPublished = publishedCultures.Contains(culture); // required index values go here diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs index 93022ee4a2..a52b2385be 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs @@ -3544,7 +3544,7 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent // verify saved state content = ContentService.GetById(content.Key)!; Assert.AreEqual(1, content.PublishedCultures.Count()); - Assert.AreEqual(langEn.IsoCode.ToLowerInvariant(), content.PublishedCultures.First()); + Assert.AreEqual(langEn.IsoCode, content.PublishedCultures.First()); } private void AssertPerCulture(IContent item, Func getter,