From dbf310caf1d6d6df9e04736acec604ad6fb2c5a6 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 30 Apr 2018 21:03:43 +0200 Subject: [PATCH] Now use empty string for invariant in published --- .../PublishedContent/CurrentVariation.cs | 8 +++---- .../PublishedContent/IPublishedContent.cs | 4 ++-- .../PublishedContent/IPublishedProperty.cs | 8 +++---- .../PublishedContentWrapped.cs | 4 ++-- .../PublishedContent/PublishedPropertyBase.cs | 8 +++---- .../PublishedContent/RawValueProperty.cs | 14 +++++------ .../ThreadCultureCurrentVariationAccessor.cs | 4 ++-- .../Strings/ContentBaseExtensions.cs | 2 -- .../Strings/DefaultShortStringHelper.cs | 10 ++++---- .../Strings/DefaultShortStringHelperConfig.cs | 6 ++--- .../Strings/DefaultUrlSegmentProvider.cs | 8 +++---- src/Umbraco.Examine/UmbracoContentIndexer.cs | 4 ++-- .../Published/NestedContentTests.cs | 8 +++---- .../PublishedContent/NuCacheTests.cs | 16 ++++++------- .../PublishedContentDataTableTests.cs | 4 ++-- .../PublishedContent/PublishedMediaTests.cs | 1 - .../SolidPublishedSnapshot.cs | 12 +++++----- .../ContentFinderByUrlWithDomainsTests.cs | 4 ++-- .../Routing/DomainsAndCulturesTests.cs | 2 +- .../TestHelpers/Stubs/TestPublishedContent.cs | 8 +++---- .../TestSystemDefaultCultureAccessor.cs | 8 ++++++- .../ExamineDemoDataContentService.cs | 2 -- .../UmbracoExamine/IndexInitializer.cs | 4 +++- src/Umbraco.Tests/UmbracoExamine/IndexTest.cs | 16 ++++--------- .../UmbracoExamine/SearchTests.cs | 2 +- .../Models/PublishedContentBase.cs | 6 ++--- .../ISystemDefaultCultureAccessor.cs | 3 +++ .../NuCache/DataSource/PropertyData.cs | 18 +++++++++++--- .../PublishedCache/NuCache/Property.cs | 24 +++++++++---------- .../NuCache/PublishedContent.cs | 10 ++++---- .../PublishedElementPropertyBase.cs | 8 +++---- .../PublishedCache/PublishedMember.cs | 2 +- .../SystemDefaultCultureAccessor.cs | 2 +- .../DictionaryPublishedContent.cs | 2 +- .../XmlPublishedCache/XmlPublishedContent.cs | 2 +- .../XmlPublishedCache/XmlPublishedProperty.cs | 6 ++--- src/Umbraco.Web/PublishedContentExtensions.cs | 4 ++-- .../PublishedContentPropertyExtension.cs | 2 +- src/Umbraco.Web/PublishedElementExtensions.cs | 6 ++--- src/Umbraco.Web/Routing/UrlProvider.cs | 22 ++++++++--------- src/Umbraco.Web/umbraco.presentation/page.cs | 16 ++++++------- 41 files changed, 154 insertions(+), 146 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/CurrentVariation.cs b/src/Umbraco.Core/Models/PublishedContent/CurrentVariation.cs index f52763ecf0..74a8c403c3 100644 --- a/src/Umbraco.Core/Models/PublishedContent/CurrentVariation.cs +++ b/src/Umbraco.Core/Models/PublishedContent/CurrentVariation.cs @@ -10,18 +10,18 @@ /// public CurrentVariation(string culture = null, string segment = null) { - Culture = culture; - Segment = segment; + Culture = culture ?? ""; // cannot be null, default to invariant + Segment = segment ?? ""; // cannot be null, default to neutral } /// /// Gets the culture. /// - public string Culture { get; set; } + public string Culture { get; } /// /// Gets the segment. /// - public string Segment { get; set; } + public string Segment { get; } } } diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs index b3358c4676..91412bce3f 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs @@ -117,12 +117,12 @@ namespace Umbraco.Core.Models.PublishedContent /// if any. In addition, when the content type is multi-lingual, this is the url for the /// specified culture. Otherwise, it is the invariant url. /// - string GetUrl(string culture = "."); + string GetUrl(string culture = null); /// /// Gets culture infos for a culture. /// - PublishedCultureInfos GetCulture(string culture = "."); + PublishedCultureInfos GetCulture(string culture = null); /// /// Gets culture infos. diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs index bfe1389921..9d2cca3e6d 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs @@ -21,7 +21,7 @@ /// Other caches that get their raw value from the database would consider that a property has "no /// value" if it is missing, null, or an empty string (including whitespace-only). /// - bool HasValue(string culture = ".", string segment = "."); + bool HasValue(string culture = null, string segment = null); /// /// Gets the source value of the property. @@ -35,7 +35,7 @@ /// If you're using that value, you're probably wrong, unless you're doing some internal /// Umbraco stuff. /// - object GetSourceValue(string culture = ".", string segment = "."); + object GetSourceValue(string culture = null, string segment = null); /// /// Gets the object value of the property. @@ -45,7 +45,7 @@ /// It can be null, or any type of CLR object. /// It has been fully prepared and processed by the appropriate converter. /// - object GetValue(string culture = ".", string segment = "."); + object GetValue(string culture = null, string segment = null); /// /// Gets the XPath value of the property. @@ -55,6 +55,6 @@ /// It must be either null, or a string, or an XPathNavigator. /// It has been fully prepared and processed by the appropriate converter. /// - object GetXPathValue(string culture = ".", string segment = "."); + object GetXPathValue(string culture = null, string segment = null); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs index 51fe3045f7..8187b7498e 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs @@ -97,10 +97,10 @@ namespace Umbraco.Core.Models.PublishedContent public virtual string Url => _content.Url; /// - public virtual string GetUrl(string culture = ".") => _content.GetUrl(culture); + public virtual string GetUrl(string culture = null) => _content.GetUrl(culture); /// - public PublishedCultureInfos GetCulture(string culture = ".") => _content.GetCulture(culture); + public PublishedCultureInfos GetCulture(string culture = null) => _content.GetCulture(culture); /// public IReadOnlyDictionary Cultures => _content.Cultures; diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs index c6626be1b2..7e2a5b5498 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs @@ -53,15 +53,15 @@ namespace Umbraco.Core.Models.PublishedContent public string Alias => PropertyType.Alias; /// - public abstract bool HasValue(string culture = ".", string segment = "."); + public abstract bool HasValue(string culture = null, string segment = null); /// - public abstract object GetSourceValue(string culture = ".", string segment = "."); + public abstract object GetSourceValue(string culture = null, string segment = null); /// - public abstract object GetValue(string culture = ".", string segment = "."); + public abstract object GetValue(string culture = null, string segment = null); /// - public abstract object GetXPathValue(string culture = ".", string segment = "."); + public abstract object GetXPathValue(string culture = null, string segment = null); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs index d7d71cea08..5dc4a280e6 100644 --- a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs @@ -23,20 +23,20 @@ namespace Umbraco.Core.Models.PublishedContent // RawValueProperty does not (yet?) support variants, // only manages the current "default" value - public override object GetSourceValue(string culture = ".", string segment = ".") - => culture == "." & segment == "." ? _sourceValue : null; + public override object GetSourceValue(string culture = null, string segment = null) + => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _sourceValue : null; - public override bool HasValue(string culture = ".", string segment = ".") + public override bool HasValue(string culture = null, string segment = null) { var sourceValue = GetSourceValue(culture, segment); return sourceValue is string s ? !string.IsNullOrWhiteSpace(s) : sourceValue != null; } - public override object GetValue(string culture = ".", string segment = ".") - => culture == "." & segment == "." ? _objectValue.Value : null; + public override object GetValue(string culture = null, string segment = null) + => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _objectValue.Value : null; - public override object GetXPathValue(string culture = ".", string segment = ".") - => culture == "." & segment == "." ? _xpathValue.Value : null; + public override object GetXPathValue(string culture = null, string segment = null) + => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _xpathValue.Value : null; public RawValueProperty(PublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false) : base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored diff --git a/src/Umbraco.Core/Models/PublishedContent/ThreadCultureCurrentVariationAccessor.cs b/src/Umbraco.Core/Models/PublishedContent/ThreadCultureCurrentVariationAccessor.cs index 9883cf9e3f..f0c9e87a29 100644 --- a/src/Umbraco.Core/Models/PublishedContent/ThreadCultureCurrentVariationAccessor.cs +++ b/src/Umbraco.Core/Models/PublishedContent/ThreadCultureCurrentVariationAccessor.cs @@ -16,8 +16,8 @@ namespace Umbraco.Core.Models.PublishedContent public CurrentVariation CurrentVariation { - get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new CurrentVariation { Culture = culture }); + get => _contexts.GetOrAdd(Thread.CurrentThread.CurrentUICulture.Name, culture => new CurrentVariation(culture)); set => throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Strings/ContentBaseExtensions.cs b/src/Umbraco.Core/Strings/ContentBaseExtensions.cs index 1ae43b96e6..c63b546cdc 100644 --- a/src/Umbraco.Core/Strings/ContentBaseExtensions.cs +++ b/src/Umbraco.Core/Strings/ContentBaseExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using Umbraco.Core.Models; @@ -21,7 +20,6 @@ namespace Umbraco.Core.Strings public static string GetUrlSegment(this IContentBase content, IEnumerable urlSegmentProviders, string culture = null) { if (content == null) throw new ArgumentNullException(nameof(content)); - if (culture == null) throw new ArgumentNullException(nameof(culture)); if (urlSegmentProviders == null) throw new ArgumentNullException(nameof(urlSegmentProviders)); var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content, culture)).FirstOrDefault(u => u != null); diff --git a/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs b/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs index d587893d99..eb06d0279a 100644 --- a/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs +++ b/src/Umbraco.Core/Strings/DefaultShortStringHelper.cs @@ -30,8 +30,6 @@ namespace Umbraco.Core.Strings _config = config.Clone(); } - public const string InvariantCulture = "xx-xx"; - // see notes for CleanAsciiString //// beware! the order is quite important here! //const string ValidStringCharactersSource = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -196,7 +194,7 @@ function validateSafeAlias(input, value, immediate, callback) {{ if (string.IsNullOrWhiteSpace(text)) return string.Empty; - culture = culture ?? InvariantCulture; + culture = culture ?? ""; text = text.ReplaceMany(Path.GetInvalidFileNameChars(), '-'); var name = Path.GetFileNameWithoutExtension(text); @@ -291,7 +289,7 @@ function validateSafeAlias(input, value, immediate, callback) {{ { // be safe if (text == null) throw new ArgumentNullException(nameof(text)); - culture = culture ?? InvariantCulture; + culture = culture ?? ""; // get config var config = _config.For(stringType, culture); @@ -374,7 +372,7 @@ function validateSafeAlias(input, value, immediate, callback) {{ int opos = 0, ipos = 0; var state = StateBreak; - culture = culture ?? InvariantCulture; + culture = culture ?? ""; caseType &= CleanStringType.CaseMask; // if we apply global ToUpper or ToLower to text here @@ -507,7 +505,7 @@ function validateSafeAlias(input, value, immediate, callback) {{ CleanStringType caseType, string culture, bool isAcronym) { var term = input.Substring(ipos, len); - var cultureInfo = culture == null || culture == InvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture); + var cultureInfo = string.IsNullOrEmpty(culture) ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture); if (isAcronym) { diff --git a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs index 7c61175836..2bbade0fd8 100644 --- a/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs +++ b/src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Strings return config; } - public string DefaultCulture { get; set; } = DefaultShortStringHelper.InvariantCulture; + public string DefaultCulture { get; set; } = ""; // invariant public Dictionary UrlReplaceCharacters { get; set; } @@ -48,7 +48,7 @@ namespace Umbraco.Core.Strings { if (config == null) throw new ArgumentNullException(nameof(config)); - culture = culture ?? DefaultShortStringHelper.InvariantCulture; + culture = culture ?? ""; if (_configs.ContainsKey(culture) == false) _configs[culture] = new Dictionary(); @@ -115,7 +115,7 @@ namespace Umbraco.Core.Strings // (the helper uses a private clone to prevent modifications) internal Config For(CleanStringType stringType, string culture) { - culture = culture ?? DefaultShortStringHelper.InvariantCulture; + culture = culture ?? ""; stringType = stringType & CleanStringType.RoleMask; Dictionary config; diff --git a/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs b/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs index 87a6bccd13..bc52e94f7b 100644 --- a/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs +++ b/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs @@ -15,16 +15,16 @@ namespace Umbraco.Core.Strings /// The url segment. public string GetUrlSegment(IContentBase content, string culture = null) { - return GetUrlSegmentSource(content).ToUrlSegment(culture); + return GetUrlSegmentSource(content, culture).ToUrlSegment(culture); } - private static string GetUrlSegmentSource(IContentBase content) + private static string GetUrlSegmentSource(IContentBase content, string culture) { string source = null; if (content.HasProperty(Constants.Conventions.Content.UrlName)) - source = (content.GetValue(Constants.Conventions.Content.UrlName) ?? string.Empty).Trim(); + source = (content.GetValue(Constants.Conventions.Content.UrlName, culture) ?? string.Empty).Trim(); if (string.IsNullOrWhiteSpace(source)) - source = content.Name; + source = content.GetName(culture); return source; } } diff --git a/src/Umbraco.Examine/UmbracoContentIndexer.cs b/src/Umbraco.Examine/UmbracoContentIndexer.cs index 0c02ce02b9..d799e12eed 100644 --- a/src/Umbraco.Examine/UmbracoContentIndexer.cs +++ b/src/Umbraco.Examine/UmbracoContentIndexer.cs @@ -321,7 +321,7 @@ namespace Umbraco.Examine { foreach (var c in content) { - var urlValue = c.GetUrlSegment(urlSegmentProviders); + var urlValue = c.GetUrlSegment(urlSegmentProviders, ""); // for now, index with invariant culture var values = new Dictionary { {"icon", new object[] {c.ContentType.Icon}}, @@ -348,7 +348,7 @@ namespace Umbraco.Examine { //only add the value if its not null or empty (we'll check for string explicitly here too) //fixme support variants with language id - var val = property.GetValue(); + var val = property.GetValue("", ""); // for now, index the invariant values switch (val) { case null: diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index ea5fa6f7e6..0bc4fb9de4 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -242,10 +242,10 @@ namespace Umbraco.Tests.Published _owner = owner; } - public override bool HasValue(string culture = ".", string segment = ".") => _hasValue; - public override object GetSourceValue(string culture = ".", string segment = ".") => _sourceValue; - public override object GetValue(string culture = ".", string segment = ".") => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview); - public override object GetXPathValue(string culture = ".", string segment = ".") => throw new WontImplementException(); + public override bool HasValue(string culture = null, string segment = null) => _hasValue; + public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue; + public override object GetValue(string culture = null, string segment = null) => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview); + public override object GetXPathValue(string culture = null, string segment = null) => throw new WontImplementException(); } class TestPublishedContent : PublishedContentBase diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index ffdaf71711..fbe6708008 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -45,9 +45,9 @@ namespace Umbraco.Tests.PublishedContent DraftData = new ContentData { Name="It Works2!", Published = false, TemplateId = 0, VersionId = 2, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary { { "prop", new[] { - new PropertyData { Value = "val2" }, - new PropertyData { Culture = "fr-FR", Value = "val-fr2" }, - new PropertyData { Culture = "en-UK", Value = "val-uk2" } + new PropertyData { Culture = "", Segment = "", Value = "val2" }, + new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr2" }, + new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk2" } } } }, CultureInfos = new Dictionary { @@ -58,9 +58,9 @@ namespace Umbraco.Tests.PublishedContent PublishedData = new ContentData { Name="It Works1!", Published = true, TemplateId = 0, VersionId = 1, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary { { "prop", new[] { - new PropertyData { Value = "val1" }, - new PropertyData { Culture = "fr-FR", Value = "val-fr1" }, - new PropertyData { Culture = "en-UK", Value = "val-uk1" } + new PropertyData { Culture = "", Segment = "", Value = "val1" }, + new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr1" }, + new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk1" } } } }, CultureInfos = new Dictionary { @@ -160,7 +160,7 @@ namespace Umbraco.Tests.PublishedContent Assert.IsNotNull(publishedContent); Assert.AreEqual("It Works1!", publishedContent.Name); Assert.AreEqual("val1", publishedContent.Value("prop")); - Assert.AreEqual("val-fr1", publishedContent.Value("prop", "fr-FR")); + Assert.AreEqual("val-fr1", publishedContent.Value("prop", "fr-FR")); // fixme wtf is happening here? Assert.AreEqual("val-uk1", publishedContent.Value("prop", "en-UK")); Assert.AreEqual("name-fr1", publishedContent.GetCulture("fr-FR").Name); @@ -190,7 +190,7 @@ namespace Umbraco.Tests.PublishedContent Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.GetCulture().Date); // invariant needs to be retrieved explicitely, when it's not default - Assert.AreEqual("val1", publishedContent.Value("prop", culture: null)); + Assert.AreEqual("val1", publishedContent.Value("prop", culture: "")); // but, // if the content type / property type does not vary, then it's all invariant again diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs index 70a349e0cb..8244600994 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs @@ -184,7 +184,7 @@ namespace Umbraco.Tests.PublishedContent private class TestPublishedContent : IPublishedContent { public string Url { get; set; } - public string GetUrl(string culture = ".") => throw new NotSupportedException(); + public string GetUrl(string culture = null) => throw new NotSupportedException(); public PublishedItemType ItemType { get; set; } @@ -204,7 +204,7 @@ namespace Umbraco.Tests.PublishedContent public int TemplateId { get; set; } public int SortOrder { get; set; } public string Name { get; set; } - public PublishedCultureInfos GetCulture(string culture = ".") => throw new NotSupportedException(); + public PublishedCultureInfos GetCulture(string culture = null) => throw new NotSupportedException(); public IReadOnlyDictionary Cultures => throw new NotSupportedException(); public string UrlSegment { get; set; } public string WriterName { get; set; } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index adfc9f535a..9fcc6125bc 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -133,7 +133,6 @@ namespace Umbraco.Tests.PublishedContent } } - [Test] public void Do_Not_Find_In_Recycle_Bin() { diff --git a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs index 7cdea14008..e502097819 100644 --- a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs +++ b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs @@ -176,7 +176,7 @@ namespace Umbraco.Tests.PublishedContent public int TemplateId { get; set; } public int SortOrder { get; set; } public string Name { get; set; } - public PublishedCultureInfos GetCulture(string culture = ".") => throw new NotSupportedException(); + public PublishedCultureInfos GetCulture(string culture = null) => throw new NotSupportedException(); public IReadOnlyDictionary Cultures => throw new NotSupportedException(); public string UrlSegment { get; set; } public string WriterName { get; set; } @@ -189,7 +189,7 @@ namespace Umbraco.Tests.PublishedContent public Guid Version { get; set; } public int Level { get; set; } public string Url { get; set; } - public string GetUrl(string culture = ".") => throw new NotSupportedException(); + public string GetUrl(string culture = null) => throw new NotSupportedException(); public PublishedItemType ItemType { get { return PublishedItemType.Content; } } public bool IsDraft { get; set; } @@ -256,10 +256,10 @@ namespace Umbraco.Tests.PublishedContent public bool SolidHasValue { get; set; } public object SolidXPathValue { get; set; } - public object GetSourceValue(string culture = ".", string segment = ".") => SolidSourceValue; - public object GetValue(string culture = ".", string segment = ".") => SolidValue; - public object GetXPathValue(string culture = ".", string segment = ".") => SolidXPathValue; - public bool HasValue(string culture = ".", string segment = ".") => SolidHasValue; + public object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue; + public object GetValue(string culture = null, string segment = null) => SolidValue; + public object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue; + public bool HasValue(string culture = null, string segment = null) => SolidHasValue; } [PublishedModel("ContentType2")] diff --git a/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs b/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs index 949467a6fe..5787d3e613 100644 --- a/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs @@ -148,7 +148,7 @@ namespace Umbraco.Tests.Routing [TestCase("http://domain1.com/fr/1001-2-1", 100121, "fr-FR")] [TestCase("http://domain1.com/1001-3", 10013, "en-US")] - [TestCase("http://domain2.com/1002", 1002, null)] + [TestCase("http://domain2.com/1002", 1002, "")] [TestCase("http://domain3.com/", 1003, "en-US")] [TestCase("http://domain3.com/en", 10031, "en-US")] @@ -158,7 +158,7 @@ namespace Umbraco.Tests.Routing [TestCase("http://domain3.com/1003-3", 10033, "en-US")] [TestCase("https://domain1.com/", 1001, "en-US")] - [TestCase("https://domain3.com/", 1001, null)] // because domain3 is explicitely set on http + [TestCase("https://domain3.com/", 1001, "")] // because domain3 is explicitely set on http public void Lookup_NestedDomains(string url, int expectedId, string expectedCulture) { diff --git a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs index e4fcfc46f8..ad6a9cf0a9 100644 --- a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs +++ b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs @@ -303,7 +303,7 @@ namespace Umbraco.Tests.Routing [TestCase("http://domain1.com/fr", "fr-FR", 10012)] // domain takes over local wildcard at 10012 [TestCase("http://domain1.com/fr/1001-2-1", "fr-FR", 100121)] // domain takes over local wildcard at 10012 - [TestCase("/1003", null, 1003)] // default culture (no domain) + [TestCase("/1003", "", 1003)] // default culture (no domain) [TestCase("/1003/1003-1", "nl-NL", 10031)] // wildcard on 10031 applies [TestCase("/1003/1003-1/1003-1-1", "nl-NL", 100311)] // wildcard on 10031 applies #endregion diff --git a/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs b/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs index 3f2a05dfda..19cb5473e3 100644 --- a/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs +++ b/src/Umbraco.Tests/TestHelpers/Stubs/TestPublishedContent.cs @@ -19,14 +19,14 @@ namespace Umbraco.Tests.TestHelpers.Stubs public int SortOrder { get; set; } public string Name { get; set; } public ICurrentVariationAccessor VariationAccessor { get; set; } - public PublishedCultureInfos GetCulture(string culture = ".") + public PublishedCultureInfos GetCulture(string culture = null) { // handle context culture - if (culture == ".") + if (culture == null) culture = VariationAccessor?.CurrentVariation.Culture; // no invariant culture infos - if (culture == null || Cultures == null) return null; + if (culture == "" || Cultures == null) return null; // get return Cultures.TryGetValue(culture, out var cultureInfos) ? cultureInfos : null; @@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers.Stubs public Guid Version { get; set; } public int Level { get; set; } public string Url { get; set; } - public string GetUrl(string culture = ".") => throw new NotSupportedException(); + public string GetUrl(string culture = null) => throw new NotSupportedException(); public PublishedItemType ItemType => ContentType.ItemType; public bool IsDraft { get; set; } public IPublishedContent Parent { get; set; } diff --git a/src/Umbraco.Tests/Testing/Objects/Accessors/TestSystemDefaultCultureAccessor.cs b/src/Umbraco.Tests/Testing/Objects/Accessors/TestSystemDefaultCultureAccessor.cs index fe94a0237f..6d78f0d290 100644 --- a/src/Umbraco.Tests/Testing/Objects/Accessors/TestSystemDefaultCultureAccessor.cs +++ b/src/Umbraco.Tests/Testing/Objects/Accessors/TestSystemDefaultCultureAccessor.cs @@ -4,6 +4,12 @@ namespace Umbraco.Tests.Testing.Objects.Accessors { public class TestSystemDefaultCultureAccessor : ISystemDefaultCultureAccessor { - public string DefaultCulture { get; set; } + private string _defaultCulture = string.Empty; + + public string DefaultCulture + { + get => _defaultCulture; + set => _defaultCulture = value ?? string.Empty; + } } } diff --git a/src/Umbraco.Tests/UmbracoExamine/ExamineDemoDataContentService.cs b/src/Umbraco.Tests/UmbracoExamine/ExamineDemoDataContentService.cs index ffbd4f82d0..5bc1fbfdaa 100644 --- a/src/Umbraco.Tests/UmbracoExamine/ExamineDemoDataContentService.cs +++ b/src/Umbraco.Tests/UmbracoExamine/ExamineDemoDataContentService.cs @@ -58,7 +58,5 @@ namespace Umbraco.Tests.UmbracoExamine } private readonly XDocument _xContent; - - } } diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs index 30bcc3766d..c7599e63e4 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs @@ -58,7 +58,8 @@ namespace Umbraco.Tests.UmbracoExamine m.SortOrder == (int)x.Attribute("sortOrder") && m.CreateDate == (DateTime)x.Attribute("createDate") && m.UpdateDate == (DateTime)x.Attribute("updateDate") && - m.Name == (string)x.Attribute("nodeName") && + m.Name == (string)x.Attribute("nodeName") && + m.GetName(It.IsAny()) == (string)x.Attribute("nodeName") && m.Path == (string)x.Attribute("path") && m.Properties == new PropertyCollection() && m.ContentType == Mock.Of(mt => @@ -102,6 +103,7 @@ namespace Umbraco.Tests.UmbracoExamine m.CreateDate == (DateTime) x.Attribute("createDate") && m.UpdateDate == (DateTime) x.Attribute("updateDate") && m.Name == (string) x.Attribute("nodeName") && + m.GetName(It.IsAny()) == (string)x.Attribute("nodeName") && m.Path == (string) x.Attribute("path") && m.Properties == new PropertyCollection() && m.ContentType == Mock.Of(mt => diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index 9d17be3476..8eb347c214 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs @@ -23,7 +23,6 @@ namespace Umbraco.Tests.UmbracoExamine [Test] public void Rebuild_Index() { - using (var luceneDir = new RandomIdRamDirectory()) using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, ScopeProvider.SqlContext, options: new UmbracoContentIndexerOptions(true, false, null))) using (indexer.ProcessNonAsync()) @@ -46,7 +45,6 @@ namespace Umbraco.Tests.UmbracoExamine [Test] public void Index_Protected_Content_Not_Indexed() { - using (var luceneDir = new RandomIdRamDirectory()) using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, ScopeProvider.SqlContext)) using (indexer.ProcessNonAsync()) @@ -178,7 +176,7 @@ namespace Umbraco.Tests.UmbracoExamine //create the whole thing indexer.RebuildIndex(); - + var result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndexer.CategoryFieldName, IndexTypes.Content).Compile()); Assert.AreEqual(21, result.TotalItemCount); @@ -188,7 +186,7 @@ namespace Umbraco.Tests.UmbracoExamine { indexer.DeleteFromIndex(r.Id); } - + //ensure it's all gone result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndexer.CategoryFieldName, IndexTypes.Content).Compile()); @@ -197,14 +195,11 @@ namespace Umbraco.Tests.UmbracoExamine //call our indexing methods indexer.IndexAll(IndexTypes.Content); - + result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndexer.CategoryFieldName, IndexTypes.Content).Compile()); Assert.AreEqual(21, result.TotalItemCount); - } - - } /// @@ -221,15 +216,13 @@ namespace Umbraco.Tests.UmbracoExamine //create the whole thing indexer.RebuildIndex(); - + //now delete a node that has children indexer.DeleteFromIndex(1140.ToString()); //this node had children: 1141 & 1142, let's ensure they are also removed - - var results = searcher.Search(searcher.CreateCriteria().Id(1141).Compile()); Assert.AreEqual(0, results.Count()); @@ -240,6 +233,5 @@ namespace Umbraco.Tests.UmbracoExamine } private readonly ExamineDemoDataMediaService _mediaService = new ExamineDemoDataMediaService(); - } } diff --git a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs index c71dc6f242..80dbe08343 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -23,7 +23,6 @@ namespace Umbraco.Tests.UmbracoExamine [Test] public void Test_Sort_Order_Sorting() { - long totalRecs; var demoData = new ExamineDemoDataContentService(TestFiles.umbraco_sort); var allRecs = demoData.GetLatestContentByXPath("//*[@isDoc]") @@ -39,6 +38,7 @@ namespace Umbraco.Tests.UmbracoExamine m.CreateDate == (DateTime)x.Attribute("createDate") && m.UpdateDate == (DateTime)x.Attribute("updateDate") && m.Name == (string)x.Attribute("nodeName") && + m.GetName(It.IsAny()) == (string)x.Attribute("nodeName") && m.Path == (string)x.Attribute("path") && m.Properties == new PropertyCollection() && m.Published == true && diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index c5a0e5ac0b..60fb746423 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.Models [DebuggerDisplay("Content Id: {Id}, Name: {Name}")] public abstract class PublishedContentBase : IPublishedContent { - private string _url; // fixme - cannot cache urls! depends on the current request! + private string _url; // fixme - cannot cache urls, they depends on the current request #region ContentType @@ -79,7 +79,7 @@ namespace Umbraco.Web.Models /// The url of documents are computed by the document url providers. The url of medias are, at the moment, /// computed here from the 'umbracoFile' property -- but we should move to media url providers at some point. /// - public virtual string GetUrl(string culture = ".") // fixme - consider .GetCulture("fr-FR").Url + public virtual string GetUrl(string culture = null) // fixme - consider .GetCulture("fr-FR").Url { switch (ItemType) { @@ -133,7 +133,7 @@ namespace Umbraco.Web.Models } /// - public abstract PublishedCultureInfos GetCulture(string culture = "."); + public abstract PublishedCultureInfos GetCulture(string culture = null); /// public abstract IReadOnlyDictionary Cultures { get; } diff --git a/src/Umbraco.Web/PublishedCache/ISystemDefaultCultureAccessor.cs b/src/Umbraco.Web/PublishedCache/ISystemDefaultCultureAccessor.cs index 109187c770..080149864b 100644 --- a/src/Umbraco.Web/PublishedCache/ISystemDefaultCultureAccessor.cs +++ b/src/Umbraco.Web/PublishedCache/ISystemDefaultCultureAccessor.cs @@ -8,6 +8,9 @@ /// /// Gets the system default culture. /// + /// + /// Implementations must NOT return a null value. Return an empty string for the invariant culture. + /// string DefaultCulture { get; } } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/PropertyData.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/PropertyData.cs index ddb9607575..9f0b3cf7fa 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/PropertyData.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/PropertyData.cs @@ -1,14 +1,26 @@ -using Newtonsoft.Json; +using System; +using Newtonsoft.Json; namespace Umbraco.Web.PublishedCache.NuCache.DataSource { internal class PropertyData { + private string _culture; + private string _segment; + [JsonProperty("culture")] - public string Culture { get; set; } + public string Culture + { + get => _culture; + set => _culture = value ?? throw new ArgumentNullException(nameof(value)); + } [JsonProperty("seg")] - public string Segment { get; set; } + public string Segment + { + get => _segment; + set => _segment = value ?? throw new ArgumentNullException(nameof(value)); + } [JsonProperty("val")] public object Value { get; set; } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs index 6231425e50..22e10c1cb7 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs @@ -52,7 +52,7 @@ namespace Umbraco.Web.PublishedCache.NuCache { foreach (var sourceValue in sourceValues) { - if (sourceValue.Culture == null && sourceValue.Segment == null) + if (sourceValue.Culture == "" && sourceValue.Segment == "") { _sourceValue = sourceValue.Value; } @@ -89,7 +89,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _variations = origin._variations; } - public override bool HasValue(string culture = ".", string segment = ".") => _sourceValue != null + public override bool HasValue(string culture = null, string segment = null) => _sourceValue != null && (!(_sourceValue is string) || string.IsNullOrWhiteSpace((string) _sourceValue) == false); // used to cache the recursive *property* for this property @@ -150,7 +150,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // this is always invoked from within a lock, so does not require its own lock private object GetInterValue(string culture, string segment) { - if (culture == null && segment == null) + if (culture == "" && segment == "") { if (_interInitialized) return _interValue; _interValue = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing); @@ -163,7 +163,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var k = new CompositeStringStringKey(culture, segment); if (!_sourceValues.TryGetValue(k, out var vvalue)) - _sourceValues[k] = vvalue = new SourceInterValue { Culture = culture, Segment = segment }; + _sourceValues[k] = vvalue = new SourceInterValue { Culture = culture, Segment = segment, SourceValue = GetSourceValue(culture, segment) }; // fixme where is the source? if (vvalue.InterInitialized) return vvalue.InterValue; vvalue.InterValue = PropertyType.ConvertSourceToInter(_content, vvalue.SourceValue, _isPreviewing); @@ -171,11 +171,11 @@ namespace Umbraco.Web.PublishedCache.NuCache return vvalue.InterValue; } - public override object GetSourceValue(string culture = ".", string segment = ".") + public override object GetSourceValue(string culture = null, string segment = null) { ContextualizeVariation(ref culture, ref segment); - if (culture == null && segment == null) + if (culture == "" && segment == "") return _sourceValue; lock (_locko) @@ -187,16 +187,16 @@ namespace Umbraco.Web.PublishedCache.NuCache private void ContextualizeVariation(ref string culture, ref string segment) { - if (culture != "." && segment != ".") return; + if (culture != null && segment != null) return; // use context values // fixme CultureSegment? var publishedVariationContext = _content.VariationAccessor?.CurrentVariation; - if (culture == ".") culture = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Culture : null; - if (segment == ".") segment = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Segment : null; + if (culture == null) culture = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Culture : ""; + if (segment == null) segment = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Segment : ""; } - public override object GetValue(string culture = ".", string segment = ".") + public override object GetValue(string culture = null, string segment = null) { ContextualizeVariation(ref culture, ref segment); @@ -217,7 +217,7 @@ namespace Umbraco.Web.PublishedCache.NuCache return value; } - public override object GetXPathValue(string culture = ".", string segment = ".") + public override object GetXPathValue(string culture = null, string segment = null) { ContextualizeVariation(ref culture, ref segment); @@ -252,7 +252,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // this is always invoked from within a lock, so does not require its own lock public CacheValue For(string culture, string segment) { - if (culture == null && segment == null) + if (culture == "" && segment == "") return this; if (_values == null) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index ea2480ec7a..5382c3e184 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -182,7 +182,7 @@ namespace Umbraco.Web.PublishedCache.NuCache return _contentData.Name; var culture = VariationAccessor.CurrentVariation.Culture; - if (culture == null) + if (culture == "") return _contentData.Name; return Cultures.TryGetValue(culture, out var cultureInfos) ? cultureInfos.Name : null; @@ -198,7 +198,7 @@ namespace Umbraco.Web.PublishedCache.NuCache return _urlSegment; var culture = VariationAccessor.CurrentVariation.Culture; - if (culture == null) + if (culture == "") return _urlSegment; return Cultures.TryGetValue(culture, out var cultureInfos) ? cultureInfos.UrlSegment : null; @@ -240,14 +240,14 @@ namespace Umbraco.Web.PublishedCache.NuCache private static readonly IReadOnlyDictionary NoCultureInfos = new Dictionary(); /// - public override PublishedCultureInfos GetCulture(string culture = ".") + public override PublishedCultureInfos GetCulture(string culture = null) { // handle context culture - if (culture == ".") + if (culture == null) culture = VariationAccessor.CurrentVariation.Culture; // no invariant culture infos - if (culture == null) return null; + if (culture == "") return null; // get return Cultures.TryGetValue(culture, out var cultureInfos) ? cultureInfos : null; diff --git a/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs b/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs index 9fa16d184c..d8db937ca8 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.PublishedCache IsMember = propertyType.ContentType.ItemType == PublishedItemType.Member; } - public override bool HasValue(string culture = ".", string segment = ".") + public override bool HasValue(string culture = null, string segment = null) => _sourceValue != null && (!(_sourceValue is string s) || !string.IsNullOrWhiteSpace(s)); // used to cache the CacheValues of this property @@ -136,9 +136,9 @@ namespace Umbraco.Web.PublishedCache return _interValue; } - public override object GetSourceValue(string culture = ".", string segment = ".") => _sourceValue; + public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue; - public override object GetValue(string culture = ".", string segment = ".") + public override object GetValue(string culture = null, string segment = null) { GetCacheLevels(out var cacheLevel, out var referenceCacheLevel); @@ -152,7 +152,7 @@ namespace Umbraco.Web.PublishedCache } } - public override object GetXPathValue(string culture = ".", string segment = ".") + public override object GetXPathValue(string culture = null, string segment = null) { GetCacheLevels(out var cacheLevel, out var referenceCacheLevel); diff --git a/src/Umbraco.Web/PublishedCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/PublishedMember.cs index 8983f1e152..c480e5f4ae 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedMember.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedMember.cs @@ -144,7 +144,7 @@ namespace Umbraco.Web.PublishedCache public override string Name => _member.Name; - public override PublishedCultureInfos GetCulture(string culture = ".") => throw new NotSupportedException(); + public override PublishedCultureInfos GetCulture(string culture = null) => throw new NotSupportedException(); public override IReadOnlyDictionary Cultures => throw new NotSupportedException(); diff --git a/src/Umbraco.Web/PublishedCache/SystemDefaultCultureAccessor.cs b/src/Umbraco.Web/PublishedCache/SystemDefaultCultureAccessor.cs index 42e1c4dbca..ced9a0e134 100644 --- a/src/Umbraco.Web/PublishedCache/SystemDefaultCultureAccessor.cs +++ b/src/Umbraco.Web/PublishedCache/SystemDefaultCultureAccessor.cs @@ -19,6 +19,6 @@ namespace Umbraco.Web.PublishedCache } /// - public string DefaultCulture => _localizationService.GetDefaultLanguageIsoCode(); // fast + public string DefaultCulture => _localizationService.GetDefaultLanguageIsoCode() ?? ""; // fast } } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs index b72425085e..45a8ebbb7a 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs @@ -154,7 +154,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache public override string Name => _name; - public override PublishedCultureInfos GetCulture(string culture = ".") => throw new NotSupportedException(); + public override PublishedCultureInfos GetCulture(string culture = null) => throw new NotSupportedException(); public override IReadOnlyDictionary Cultures => throw new NotSupportedException(); diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index 3ad30b4d3f..f85f8f8640 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -150,7 +150,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache } } - public override PublishedCultureInfos GetCulture(string culture = ".") => throw new NotSupportedException(); + public override PublishedCultureInfos GetCulture(string culture = null) => throw new NotSupportedException(); public override IReadOnlyDictionary Cultures => throw new NotSupportedException(); diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs index 57b81b8c73..ea8ab925c6 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs @@ -27,13 +27,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache /// /// Gets the raw value of the property. /// - public override object GetSourceValue(string culture = ".", string segment = ".") => _sourceValue; + public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue; // in the Xml cache, everything is a string, and to have a value // you want to have a non-null, non-empty string. - public override bool HasValue(string culture = ".", string segment = ".") => _sourceValue.Trim().Length > 0; + public override bool HasValue(string culture = null, string segment = null) => _sourceValue.Trim().Length > 0; - public override object GetValue(string culture = ".", string segment = ".") + public override object GetValue(string culture = null, string segment = null) { // NOT caching the source (intermediate) value since we'll never need it // everything in Xml cache is per-request anyways diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 3b4c976d70..4edd6b3016 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -139,7 +139,7 @@ namespace Umbraco.Web /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static object Value(this IPublishedContent content, string alias, string culture = ".", string segment = ".", object defaultValue = default, bool recurse = false) + public static object Value(this IPublishedContent content, string alias, string culture = null, string segment = null, object defaultValue = default, bool recurse = false) { // fixme - refactor with fallback var property = content.GetProperty(alias, recurse); @@ -168,7 +168,7 @@ namespace Umbraco.Web /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static T Value(this IPublishedContent content, string alias, string culture = ".", string segment = ".", T defaultValue = default, bool recurse = false) + public static T Value(this IPublishedContent content, string alias, string culture = null, string segment = null, T defaultValue = default, bool recurse = false) { // fixme - refactor with fallback var property = content.GetProperty(alias, recurse); diff --git a/src/Umbraco.Web/PublishedContentPropertyExtension.cs b/src/Umbraco.Web/PublishedContentPropertyExtension.cs index e460445c6c..d57c2437a8 100644 --- a/src/Umbraco.Web/PublishedContentPropertyExtension.cs +++ b/src/Umbraco.Web/PublishedContentPropertyExtension.cs @@ -10,7 +10,7 @@ namespace Umbraco.Web { #region Value - public static T Value(this IPublishedProperty property, string culture = ".", string segment = ".", T defaultValue = default) + public static T Value(this IPublishedProperty property, string culture = null, string segment = null, T defaultValue = default) { // for Value when defaultValue is not specified, and HasValue() is false, we still want to convert the result (see below) // but we have no way to tell whether default value is specified or not - we could do it with overloads, but then defaultValue diff --git a/src/Umbraco.Web/PublishedElementExtensions.cs b/src/Umbraco.Web/PublishedElementExtensions.cs index a7776bb374..2529146b17 100644 --- a/src/Umbraco.Web/PublishedElementExtensions.cs +++ b/src/Umbraco.Web/PublishedElementExtensions.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web /// Gets a value indicating whether the content has a value for a property identified by its alias. /// /// Returns true if GetProperty(alias) is not null and GetProperty(alias).HasValue is true. - public static bool HasValue(this IPublishedElement content, string alias, string culture = ".", string segment = ".") + public static bool HasValue(this IPublishedElement content, string alias, string culture = null, string segment = null) { var prop = content.GetProperty(alias); return prop != null && prop.HasValue(culture, segment); @@ -92,7 +92,7 @@ namespace Umbraco.Web /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static object Value(this IPublishedElement content, string alias, string culture = ".", string segment = ".", object defaultValue = default) + public static object Value(this IPublishedElement content, string alias, string culture = null, string segment = null, object defaultValue = default) { var property = content.GetProperty(alias); if (property == null || !property.HasValue(culture, segment)) return defaultValue; @@ -121,7 +121,7 @@ namespace Umbraco.Web /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static T Value(this IPublishedElement content, string alias, string culture = ".", string segment = ".", T defaultValue = default) + public static T Value(this IPublishedElement content, string alias, string culture = null, string segment = null, T defaultValue = default) { var property = content.GetProperty(alias); if (property == null) return defaultValue; diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index b88245b917..d2fba48472 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -79,7 +79,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(IPublishedContent content, string culture = ".", Uri current = null) + public string GetUrl(IPublishedContent content, string culture = null, Uri current = null) => GetUrl(content, Mode, culture, current); /// @@ -94,7 +94,7 @@ namespace Umbraco.Web.Routing /// The url is absolute or relative depending on Mode and on current, unless /// absolute is true, in which case the url is always absolute. /// - public string GetUrl(IPublishedContent content, bool absolute, Uri current = null, string culture = ".") + public string GetUrl(IPublishedContent content, bool absolute, Uri current = null, string culture = null) => GetUrl(content, GetMode(absolute), culture, current); /// @@ -105,7 +105,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(IPublishedContent content, UrlProviderMode mode, Uri current = null, string culture = ".") + public string GetUrl(IPublishedContent content, UrlProviderMode mode, Uri current = null, string culture = null) => GetUrl(content, mode, culture, current); /// @@ -115,7 +115,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(Guid id, string culture = ".", Uri current = null) + public string GetUrl(Guid id, string culture = null, Uri current = null) => GetUrl(GetDocument(id), Mode, culture, current); /// @@ -130,7 +130,7 @@ namespace Umbraco.Web.Routing /// The url is absolute or relative depending on Mode and on current, unless /// absolute is true, in which case the url is always absolute. /// - public string GetUrl(Guid id, bool absolute, string culture = ".", Uri current = null) + public string GetUrl(Guid id, bool absolute, string culture = null, Uri current = null) => GetUrl(GetDocument(id), GetMode(absolute), culture, current); /// @@ -141,7 +141,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(Guid id, UrlProviderMode mode, string culture = ".", Uri current = null) + public string GetUrl(Guid id, UrlProviderMode mode, string culture = null, Uri current = null) => GetUrl(GetDocument(id), mode, culture, current); /// @@ -151,7 +151,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(int id, string culture = ".", Uri current = null) + public string GetUrl(int id, string culture = null, Uri current = null) => GetUrl(GetDocument(id), Mode, culture, current); /// @@ -166,7 +166,7 @@ namespace Umbraco.Web.Routing /// The url is absolute or relative depending on Mode and on current, unless /// absolute is true, in which case the url is always absolute. /// - public string GetUrl(int id, bool absolute, string culture = ".", Uri current = null) + public string GetUrl(int id, bool absolute, string culture = null, Uri current = null) => GetUrl(GetDocument(id), GetMode(absolute), culture, current); /// @@ -177,7 +177,7 @@ namespace Umbraco.Web.Routing /// A culture. /// The current absolute url. /// The url for the published content. - public string GetUrl(int id, UrlProviderMode mode, string culture = ".", Uri current = null) + public string GetUrl(int id, UrlProviderMode mode, string culture = null, Uri current = null) => GetUrl(GetDocument(id), mode, culture, current); /// @@ -194,13 +194,13 @@ namespace Umbraco.Web.Routing /// when no culture is specified, the current culture. /// If the provider is unable to provide a url, it returns "#". /// - public string GetUrl(IPublishedContent content, UrlProviderMode mode, string culture = ".", Uri current = null) + public string GetUrl(IPublishedContent content, UrlProviderMode mode, string culture = null, Uri current = null) { if (content == null) return "#"; // this the ONLY place where we deal with default culture - IUrlProvider always receive a culture - if (culture == ".") + if (culture == null) { culture = content.ContentType.Variations.Has(ContentVariation.CultureNeutral) // fixme CultureSegment ? _variationAccessor.CurrentVariation.Culture diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs index f7660987ea..e3643aea2c 100644 --- a/src/Umbraco.Web/umbraco.presentation/page.cs +++ b/src/Umbraco.Web/umbraco.presentation/page.cs @@ -374,17 +374,17 @@ namespace umbraco _content = content; } - public override bool HasValue(string culture = ".", string segment = ".") + public override bool HasValue(string culture = null, string segment = null) { return _sourceValue != null && ((_sourceValue is string) == false || string.IsNullOrWhiteSpace((string)_sourceValue) == false); } - public override object GetSourceValue(string culture = ".", string segment = ".") + public override object GetSourceValue(string culture = null, string segment = null) { return _sourceValue; } - public override object GetValue(string culture = ".", string segment = ".") + public override object GetValue(string culture = null, string segment = null) { // isPreviewing is true here since we want to preview anyway... const bool isPreviewing = true; @@ -392,7 +392,7 @@ namespace umbraco return PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Unknown, source, isPreviewing); } - public override object GetXPathValue(string culture = ".", string segment = ".") + public override object GetXPathValue(string culture = null, string segment = null) { throw new NotImplementedException(); } @@ -476,14 +476,14 @@ namespace umbraco get { return _inner.Name; } } - public PublishedCultureInfos GetCulture(string culture = ".") + public PublishedCultureInfos GetCulture(string culture = null) { // handle context culture - if (culture == ".") + if (culture == null) culture = _variationAccessor.CurrentVariation.Culture; // no invariant culture infos - if (culture == null) return null; + if (culture == "") return null; // get return Cultures.TryGetValue(culture, out var cultureInfos) ? cultureInfos : null; @@ -564,7 +564,7 @@ namespace umbraco get { throw new NotImplementedException(); } } - public string GetUrl(string culture = ".") => throw new NotSupportedException(); + public string GetUrl(string culture = null) => throw new NotSupportedException(); public PublishedItemType ItemType {