Skip to content

Commit c6d28f0

Browse files
Check for null in DefaultShortStringHelperConfig.WithDefault
1 parent 040116c commit c6d28f0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Umbraco.Cms.Core.Configuration.Models;
5+
using Umbraco.Cms.Core.Configuration.UmbracoSettings;
56
using Umbraco.Extensions;
67

78
namespace Umbraco.Cms.Core.Strings
@@ -60,7 +61,18 @@ public DefaultShortStringHelperConfig WithConfig(string culture, CleanStringType
6061
/// <returns>The short string helper.</returns>
6162
public DefaultShortStringHelperConfig WithDefault(RequestHandlerSettings requestHandlerSettings)
6263
{
63-
UrlReplaceCharacters = requestHandlerSettings.CharCollection
64+
// CharCollection could potentially be null if not invoked first by the framework, for instance in tests, so ensure that it's initialized.
65+
IEnumerable<IChar> charCollection = requestHandlerSettings.CharCollection;
66+
if (charCollection is null)
67+
{
68+
charCollection = requestHandlerSettings.CharCollection;
69+
if (charCollection is null)
70+
{
71+
throw new ArgumentNullException(nameof(requestHandlerSettings.CharCollection));
72+
}
73+
}
74+
75+
UrlReplaceCharacters = charCollection
6476
.Where(x => string.IsNullOrEmpty(x.Char) == false)
6577
.ToDictionary(x => x.Char, x => x.Replacement);
6678

0 commit comments

Comments
 (0)