diff --git a/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs b/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs
index 64625f153b..ef67d40102 100644
--- a/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs
+++ b/src/Umbraco.Core/Configuration/Models/RuntimeSettings.cs
@@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Configuration.Models
public int? MaxQueryStringLength { get; set; }
///
- /// Gets or sets a value for the maximum request length.
+ /// Gets or sets a value for the maximum request length in kb.
///
public int? MaxRequestLength { get; set; }
}
diff --git a/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs b/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs
index 57c69ee9aa..9b3674b07b 100644
--- a/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs
+++ b/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
@@ -267,7 +268,7 @@ namespace Umbraco.Extensions
/// Array of start content nodes
public static int[] GetStartContentNodes(this ClaimsIdentity identity) =>
identity.FindAll(x => x.Type == Constants.Security.StartContentNodeIdClaimType)
- .Select(node => int.TryParse(node.Value, out var i) ? i : default)
+ .Select(node => int.TryParse(node.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : default)
.Where(x => x != default).ToArray();
///
@@ -277,7 +278,7 @@ namespace Umbraco.Extensions
/// Array of start media nodes
public static int[] GetStartMediaNodes(this ClaimsIdentity identity) =>
identity.FindAll(x => x.Type == Constants.Security.StartMediaNodeIdClaimType)
- .Select(node => int.TryParse(node.Value, out var i) ? i : default)
+ .Select(node => int.TryParse(node.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : default)
.Where(x => x != default).ToArray();
///
@@ -293,7 +294,7 @@ namespace Umbraco.Extensions
///
///
/// User ID as integer
- public static int GetId(this ClaimsIdentity identity) => int.Parse(identity.FindFirstValue(ClaimTypes.NameIdentifier));
+ public static int GetId(this ClaimsIdentity identity) => int.Parse(identity.FindFirstValue(ClaimTypes.NameIdentifier), CultureInfo.InvariantCulture);
///
/// Get the real name belonging to the user from a ClaimsIdentity
diff --git a/src/Umbraco.Core/Extensions/ObjectExtensions.cs b/src/Umbraco.Core/Extensions/ObjectExtensions.cs
index db2d63b643..d666046e4b 100644
--- a/src/Umbraco.Core/Extensions/ObjectExtensions.cs
+++ b/src/Umbraco.Core/Extensions/ObjectExtensions.cs
@@ -6,6 +6,7 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@@ -94,8 +95,8 @@ namespace Umbraco.Extensions
{
// sure, null can be any object
return Attempt.Succeed((T)input);
- }
- }
+ }
+ }
// just try to cast
try
@@ -293,7 +294,7 @@ namespace Umbraco.Extensions
{
if (target == typeof(int))
{
- if (int.TryParse(input, out var value))
+ if (int.TryParse(input, out var value))
{
return Attempt
public class MemberIdentityUser : UmbracoIdentityUser
{
- private string _comments;
+ private string _comments;
// Custom comparer for enumerables
private static readonly DelegateEqualityComparer> s_groupsComparer = new DelegateEqualityComparer>(
@@ -77,7 +78,7 @@ namespace Umbraco.Cms.Core.Security
///
public string MemberTypeAlias { get; set; }
- private static string UserIdToString(int userId) => string.Intern(userId.ToString());
+ private static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
// TODO: Should we support custom member properties for persistence/retrieval?
}
diff --git a/src/Umbraco.Infrastructure/Security/MemberRoleStore.cs b/src/Umbraco.Infrastructure/Security/MemberRoleStore.cs
index 685a21d175..03339fbd33 100644
--- a/src/Umbraco.Infrastructure/Security/MemberRoleStore.cs
+++ b/src/Umbraco.Infrastructure/Security/MemberRoleStore.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -71,7 +72,7 @@ namespace Umbraco.Cms.Core.Security
throw new ArgumentNullException(nameof(role));
}
- if (!int.TryParse(role.Id, out int roleId))
+ if (!int.TryParse(role.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out int roleId))
{
return Task.FromResult(IdentityResult.Failed(_intParseError));
}
@@ -103,7 +104,7 @@ namespace Umbraco.Cms.Core.Security
throw new ArgumentNullException(nameof(role));
}
- if (!int.TryParse(role.Id, out int roleId))
+ if (!int.TryParse(role.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out int roleId))
{
throw new ArgumentException("The Id of the role is not an integer");
}
@@ -184,7 +185,7 @@ namespace Umbraco.Cms.Core.Security
IMemberGroup memberGroup;
// member group can be found by int or Guid, so try both
- if (!int.TryParse(roleId, out int id))
+ if (!int.TryParse(roleId, NumberStyles.Integer, CultureInfo.InvariantCulture, out int id))
{
if (!Guid.TryParse(roleId, out Guid guid))
{
diff --git a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
index 70cfcc3bfb..086ff6a66c 100644
--- a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
+++ b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
+using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -116,16 +117,14 @@ namespace Umbraco.Cms.Core.Security
throw new ArgumentNullException(nameof(user));
}
- Attempt asInt = user.Id.TryConvertTo();
- if (asInt == false)
+ if (!int.TryParse(user.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt))
{
//TODO: should this be thrown, or an identity result?
- throw new InvalidOperationException("The user id must be an integer to work with Umbraco");
+ throw new InvalidOperationException("The user id must be an integer to work with the Umbraco");
}
-
using IScope scope = _scopeProvider.CreateScope(autoComplete: true);
- IMember found = _memberService.GetById(asInt.Result);
+ IMember found = _memberService.GetById(asInt);
if (found != null)
{
// we have to remember whether Logins property is dirty, since the UpdateMemberProperties will reset it.
diff --git a/src/Umbraco.Infrastructure/Security/UmbracoUserStore.cs b/src/Umbraco.Infrastructure/Security/UmbracoUserStore.cs
index 3884ee31a1..6a2325c316 100644
--- a/src/Umbraco.Infrastructure/Security/UmbracoUserStore.cs
+++ b/src/Umbraco.Infrastructure/Security/UmbracoUserStore.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Globalization;
using System.Linq;
using System.Security.Claims;
using System.Threading;
@@ -28,16 +29,15 @@ namespace Umbraco.Cms.Core.Security
protected static int UserIdToInt(string userId)
{
- Attempt attempt = userId.TryConvertTo();
- if (attempt.Success)
+ if(int.TryParse(userId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
{
- return attempt.Result;
+ return result;
}
- throw new InvalidOperationException("Unable to convert user ID to int", attempt.Exception);
+ throw new InvalidOperationException($"Unable to convert user ID ({userId})to int using InvariantCulture");
}
- protected static string UserIdToString(int userId) => string.Intern(userId.ToString());
+ protected static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
///
/// Not supported in Umbraco
diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
index dceae58446..15490bcd04 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
@@ -535,7 +535,8 @@ namespace Umbraco.Cms.Core.Services.Implement
var rootId = Cms.Core.Constants.System.RootString;
var ids = content.Path.Split(Constants.CharArrays.Comma)
- .Where(x => x != rootId && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(int.Parse).ToArray();
+ .Where(x => x != rootId && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(s =>
+ int.Parse(s, CultureInfo.InvariantCulture)).ToArray();
if (ids.Any() == false)
return new List();
diff --git a/src/Umbraco.Infrastructure/Services/Implement/ExternalLoginService.cs b/src/Umbraco.Infrastructure/Services/Implement/ExternalLoginService.cs
index 259d6e8739..079971be24 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/ExternalLoginService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/ExternalLoginService.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Events;
@@ -25,7 +26,7 @@ namespace Umbraco.Cms.Core.Services.Implement
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
// TODO: This is temp until we update the external service to support guids for both users and members
- var asString = userId.ToString();
+ var asString = userId.ToString(CultureInfo.InvariantCulture);
return _externalLoginRepository.Get(Query().Where(x => x.UserId == asString))
.ToList();
}
@@ -36,7 +37,7 @@ namespace Umbraco.Cms.Core.Services.Implement
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
// TODO: This is temp until we update the external service to support guids for both users and members
- var asString = userId.ToString();
+ var asString = userId.ToString(CultureInfo.InvariantCulture);
return _externalLoginRepository.Get(Query().Where(x => x.UserId == asString))
.ToList();
}
diff --git a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
index 0239ad8e60..0aa49cde44 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs
@@ -485,7 +485,7 @@ namespace Umbraco.Cms.Core.Services.Implement
var rootId = Cms.Core.Constants.System.RootString;
var ids = media.Path.Split(Constants.CharArrays.Comma)
.Where(x => x != rootId && x != media.Id.ToString(CultureInfo.InvariantCulture))
- .Select(int.Parse)
+ .Select(s => int.Parse(s, CultureInfo.InvariantCulture))
.ToArray();
if (ids.Any() == false)
return new List();
diff --git a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs
index dc45319d12..447143092a 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs
@@ -83,7 +83,7 @@ namespace Umbraco.Cms.Core.Services.Implement
if (entitiesL.Count == 0) return;
//put all entity's paths into a list with the same indices
- var paths = entitiesL.Select(x => x.Path.Split(Constants.CharArrays.Comma).Select(int.Parse).ToArray()).ToArray();
+ var paths = entitiesL.Select(x => x.Path.Split(Constants.CharArrays.Comma).Select(s => int.Parse(s, CultureInfo.InvariantCulture)).ToArray()).ToArray();
// lazily get versions
var prevVersionDictionary = new Dictionary();
diff --git a/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs b/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs
index 419881fe1c..90184cd258 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Events;
@@ -57,7 +58,7 @@ namespace Umbraco.Cms.Core.Services.Implement
//Get all ids in the path for the content item and ensure they all
// parse to ints that are not -1.
var ids = contentPath.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
- .Select(x => int.TryParse(x, out int val) ? val : -1)
+ .Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out int val) ? val : -1)
.Where(x => x != -1)
.ToList();
diff --git a/src/Umbraco.Infrastructure/Sync/LastSyncedFileManager.cs b/src/Umbraco.Infrastructure/Sync/LastSyncedFileManager.cs
index 3b3351fd93..462eb88239 100644
--- a/src/Umbraco.Infrastructure/Sync/LastSyncedFileManager.cs
+++ b/src/Umbraco.Infrastructure/Sync/LastSyncedFileManager.cs
@@ -52,7 +52,7 @@ namespace Umbraco.Cms.Infrastructure.Sync
if (File.Exists(distCacheFilePath))
{
var content = File.ReadAllText(distCacheFilePath);
- if (int.TryParse(content, out var last))
+ if (int.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out var last))
{
return last;
}
diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs
index f26b53775f..875e6d2ffc 100644
--- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs
+++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs
@@ -82,7 +82,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
var pos = route.IndexOf('/');
var path = pos == 0 ? route : route.Substring(pos);
- var startNodeId = pos == 0 ? 0 : int.Parse(route.Substring(0, pos));
+ var startNodeId = pos == 0 ? 0 : int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture);
var parts = path.Split(Constants.CharArrays.ForwardSlash, StringSplitOptions.RemoveEmptyEntries);
IPublishedContent content;
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/TryConvertToTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/TryConvertToTests.cs
index 0525a24173..2c399d0e93 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/TryConvertToTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/TryConvertToTests.cs
@@ -1,7 +1,8 @@
-// Copyright (c) Umbraco.
+// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
+using System.Globalization;
using NUnit.Framework;
using Umbraco.Extensions;
@@ -46,10 +47,23 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.CoreThings
Assert.AreEqual(false, conv.Result);
}
+
[Test]
- public void ConvertToIntegerTest()
+ [TestCase("en-US")]
+ [TestCase(null)]
+ [TestCase("da-DK")]
+ [TestCase("tr-TR")]
+ public void ConvertToIntegerTest(string culture)
{
- var conv = "100".TryConvertTo();
+ if (culture is not null)
+ {
+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);
+ }
+ var conv = "-1".TryConvertTo();
+ Assert.IsTrue(conv);
+ Assert.AreEqual(-1, conv.Result);
+
+ conv = "100".TryConvertTo();
Assert.IsTrue(conv);
Assert.AreEqual(100, conv.Result);
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Authorization/AdminUsersHandlerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Authorization/AdminUsersHandlerTests.cs
index 191381d8c5..7b638c29d1 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Authorization/AdminUsersHandlerTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Authorization/AdminUsersHandlerTests.cs
@@ -2,6 +2,7 @@
// See LICENSE for more details.
using System.Collections.Generic;
+using System.Globalization;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
@@ -59,7 +60,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
public async Task Editing_Single_Admin_User_By_Admin_User_Is_Authorized()
{
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
- AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(), editingWithAdmin: true);
+ AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture), editingWithAdmin: true);
await sut.HandleAsync(authHandlerContext);
@@ -70,7 +71,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
public async Task Editing_Single_Admin_User_By_Non_Admin_User_Is_Not_Authorized()
{
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
- AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString());
+ AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture));
await sut.HandleAsync(authHandlerContext);
@@ -81,7 +82,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
public async Task Editing_Single_Non_Admin_User_By_Non_Admin_User_Is_Authorized()
{
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
- AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString());
+ AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString(CultureInfo.InvariantCulture));
await sut.HandleAsync(authHandlerContext);
diff --git a/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
index 64649ac274..1f760de4fd 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/AdminUsersHandler.cs
@@ -2,6 +2,7 @@
// See LICENSE for more details.
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
@@ -55,7 +56,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
}
int[] userIds;
- if (int.TryParse(queryString, out var userId))
+ if (int.TryParse(queryString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var userId))
{
userIds = new[] { userId };
}
diff --git a/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs b/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
index 531b92a7e9..e8433dd1a8 100644
--- a/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Authorization/PermissionsQueryStringHandler.cs
@@ -2,6 +2,7 @@
// See LICENSE for more details.
using System;
+using System.Globalization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core;
@@ -61,7 +62,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
// It might be a udi, so check that next.
// Otherwise treat it as a guid - unlikely we ever get here.
// Failing that, we can't parse it.
- if (int.TryParse(argument, out int parsedId))
+ if (int.TryParse(argument, NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsedId))
{
nodeId = parsedId;
return true;
diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
index e79b49ace3..f159011d80 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
@@ -510,7 +511,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[AllowAnonymous]
public async Task PostSetPassword(SetPasswordModel model)
{
- var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString());
+ var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString(CultureInfo.InvariantCulture));
var result = await _userManager.ResetPasswordAsync(identityUser, model.ResetCode, model.Password);
if (result.Succeeded)
@@ -560,7 +561,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
}
}
- _userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString());
+ _userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString(CultureInfo.InvariantCulture));
return Ok();
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
index 237aad6bd3..b6df2ebf4a 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
@@ -348,7 +348,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[AllowAnonymous]
public async Task ValidatePasswordResetCode([Bind(Prefix = "u")]int userId, [Bind(Prefix = "r")]string resetCode)
{
- var user = await _userManager.FindByIdAsync(userId.ToString());
+ var user = await _userManager.FindByIdAsync(userId.ToString(CultureInfo.InvariantCulture));
if (user != null)
{
var result = await _userManager.VerifyUserTokenAsync(user, "Default", "ResetPassword", resetCode);
diff --git a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs
index 1435eb6c52..ba6ca36085 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs
@@ -250,7 +250,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[ValidateAngularAntiForgeryToken]
public async Task> GetCurrentUserLinkedLogins()
{
- var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString());
+ var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture));
// deduplicate in case there are duplicates (there shouldn't be now since we have a unique constraint on the external logins
// but there didn't used to be)
diff --git a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs
index 8ee4ee1182..4d0e2cfe14 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
@@ -202,7 +203,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
public ActionResult PostSave(DictionarySave dictionary)
{
var dictionaryItem =
- _localizationService.GetDictionaryItemById(int.Parse(dictionary.Id.ToString()));
+ _localizationService.GetDictionaryItemById(int.Parse(dictionary.Id.ToString(), CultureInfo.InvariantCulture));
if (dictionaryItem == null)
return ValidationProblem("Dictionary item does not exist");
diff --git a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
index 944f1946bf..2eaeee3d12 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Http;
@@ -218,7 +219,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return foundContentResult;
}
- return new ActionResult>(foundContent.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
+ return new ActionResult>(foundContent.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(
+ s => int.Parse(s, CultureInfo.InvariantCulture)));
}
///
@@ -236,7 +238,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return foundContentResult;
}
- return new ActionResult>(foundContent.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
+ return new ActionResult>(foundContent.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).Select(
+ s => int.Parse(s, CultureInfo.InvariantCulture)));
}
///
@@ -576,7 +579,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
string filter = "",
Guid? dataTypeKey = null)
{
- if (int.TryParse(id, out var intId))
+ if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
{
return GetPagedChildren(intId, type, pageNumber, pageSize, orderBy, orderDirection, filter);
}
@@ -859,7 +862,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
{
// TODO: Need to check for Object types that support hierarchic here, some might not.
- var ids = _entityService.Get(id).Path.Split(Constants.CharArrays.Comma).Select(int.Parse).Distinct().ToArray();
+ var ids = _entityService.Get(id).Path.Split(Constants.CharArrays.Comma).Select(s => int.Parse(s, CultureInfo.InvariantCulture)).Distinct().ToArray();
var ignoreUserStartNodes = IsDataTypeIgnoringUserStartNodes(queryStrings?.GetValue("dataTypeId"));
if (ignoreUserStartNodes == false)
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs b/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs
index 84ff7565cc..834d8cc565 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
@@ -184,7 +185,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return ValidationProblem("Name cannnot be more than 255 characters in length.");
}
- var macro = _macroService.GetById(int.Parse(macroDisplay.Id.ToString()));
+ var macro = _macroService.GetById(int.Parse(macroDisplay.Id.ToString(), CultureInfo.InvariantCulture));
if (macro == null)
{
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
index e8947dbf17..d54bd7a093 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Mime;
@@ -898,7 +899,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
}
//if it's not an INT then we'll check for GUID
- if (int.TryParse(parentId, out intParentId) == false)
+ if (int.TryParse(parentId, NumberStyles.Integer, CultureInfo.InvariantCulture, out intParentId) == false)
{
// if a guid then try to look up the entity
Guid idGuid;
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberGroupController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberGroupController.cs
index 81303ba55e..fb5286505e 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MemberGroupController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MemberGroupController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -122,7 +123,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
public ActionResult PostSave(MemberGroupSave saveModel)
{
- var id = int.Parse(saveModel.Id.ToString());
+ var id = int.Parse(saveModel.Id.ToString(), CultureInfo.InvariantCulture);
IMemberGroup memberGroup = id > 0 ? _memberGroupService.GetById(id) : new MemberGroup();
if (memberGroup == null)
{
diff --git a/src/Umbraco.Web.BackOffice/Controllers/TemplateQueryController.cs b/src/Umbraco.Web.BackOffice/Controllers/TemplateQueryController.cs
index 7f5298066a..d0aadac744 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/TemplateQueryController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/TemplateQueryController.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.Linq;
using System.Text;
using Umbraco.Cms.Core;
@@ -189,7 +190,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
switch (condition.Property.Type)
{
case "int":
- return int.Parse(condition.ConstraintValue);
+ return int.Parse(condition.ConstraintValue, CultureInfo.InvariantCulture);
case "datetime":
DateTime dt;
return DateTime.TryParse(condition.ConstraintValue, out dt) ? dt : DateTime.Today;
diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs
index 39432703a7..178d9d50f0 100644
--- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs
+++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs
@@ -168,9 +168,6 @@ namespace Umbraco.Cms.Web.BackOffice.Filters
BackOfficeIdentityUser backOfficeIdentityUser = _umbracoMapper.Map(user);
await _backOfficeSignInManager.SignInAsync(backOfficeIdentityUser, isPersistent: true);
- // ensure the remainder of the request has the correct principal set
- actionContext.HttpContext.SetPrincipalForRequest(ClaimsPrincipal.Current);
-
// flag that we've made changes
_requestCache.Set(nameof(CheckIfUserTicketDataIsStaleFilter), true);
}
diff --git a/src/Umbraco.Web.BackOffice/Install/CreateUnattendedUserNotificationHandler.cs b/src/Umbraco.Web.BackOffice/Install/CreateUnattendedUserNotificationHandler.cs
index 3990f42aa7..6eaed2f42d 100644
--- a/src/Umbraco.Web.BackOffice/Install/CreateUnattendedUserNotificationHandler.cs
+++ b/src/Umbraco.Web.BackOffice/Install/CreateUnattendedUserNotificationHandler.cs
@@ -76,10 +76,10 @@ namespace Umbraco.Cms.Web.BackOffice.Install
// Uses same approach as NewInstall Step
using IServiceScope scope = _serviceScopeFactory.CreateScope();
IBackOfficeUserManager backOfficeUserManager = scope.ServiceProvider.GetRequiredService();
- BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserId.ToString());
+ BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserIdAsString);
if (membershipUser == null)
{
- throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserId}.");
+ throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserIdAsString}.");
}
//To change the password here we actually need to reset it since we don't have an old one to use to change
diff --git a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs
index 0dd19d7db9..e234fa1115 100644
--- a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs
+++ b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
@@ -330,7 +331,7 @@ namespace Umbraco.Cms.Web.BackOffice.Mapping
if (parent == null)
return false;
- var pathParts = parent.Path.Split(Constants.CharArrays.Comma).Select(x => int.TryParse(x, out var i) ? i : 0).ToList();
+ var pathParts = parent.Path.Split(Constants.CharArrays.Comma).Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : 0).ToList();
// reduce the path parts so we exclude top level content items that
// are higher up than a user's start nodes
diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs
index a47987667f..75cd5ab5a1 100644
--- a/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs
+++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Notifications;
@@ -55,7 +56,7 @@ namespace Umbraco.Cms.Web.BackOffice.Security
private void WriteAudit(string performingId, string affectedId, string ipAddress, string eventType, string eventDetails, string affectedDetails = null)
{
IUser performingUser = null;
- if (int.TryParse(performingId, out int asInt))
+ if (int.TryParse(performingId, NumberStyles.Integer, CultureInfo.InvariantCulture, out int asInt))
{
performingUser = _userService.GetUserById(asInt);
}
@@ -64,12 +65,12 @@ namespace Umbraco.Cms.Web.BackOffice.Security
? $"User UNKNOWN:{performingId}"
: $"User \"{performingUser.Name}\" {FormatEmail(performingUser)}";
- if (!int.TryParse(performingId, out int performingIdAsInt))
+ if (!int.TryParse(performingId, NumberStyles.Integer, CultureInfo.InvariantCulture, out int performingIdAsInt))
{
performingIdAsInt = 0;
}
- if (!int.TryParse(affectedId, out int affectedIdAsInt))
+ if (!int.TryParse(affectedId, NumberStyles.Integer, CultureInfo.InvariantCulture, out int affectedIdAsInt))
{
affectedIdAsInt = 0;
}
diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs
index 1457732c53..1767386088 100644
--- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs
+++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeCookieOptions.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
@@ -190,7 +191,7 @@ namespace Umbraco.Cms.Web.BackOffice.Security
// occurs when sign in is successful and after the ticket is written to the outbound cookie
// When we are signed in with the cookie, assign the principal to the current HttpContext
- ctx.HttpContext.User = ctx.Principal;
+ ctx.HttpContext.SetPrincipalForRequest(ctx.Principal);
return Task.CompletedTask;
},
diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ContentBlueprintTreeController.cs
index 9b6ccf91f6..abf3854f5b 100644
--- a/src/Umbraco.Web.BackOffice/Trees/ContentBlueprintTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/ContentBlueprintTreeController.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -130,7 +131,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
return menu;
}
- var cte = _entityService.Get(int.Parse(id), UmbracoObjectTypes.DocumentType);
+ var cte = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.DocumentType);
//only refresh & create if it's a content type
if (cte != null)
{
diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs
index 011cbe74e6..74c456026d 100644
--- a/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -187,7 +188,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
//return a normal node menu:
int iid;
- if (int.TryParse(id, out iid) == false)
+ if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out iid) == false)
{
return NotFound();
}
diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs
index e84338fc9b..2f27f8adac 100644
--- a/src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -71,7 +72,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
int asInt;
Guid asGuid = Guid.Empty;
- if (int.TryParse(id, out asInt) == false)
+ if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out asInt) == false)
{
if (Guid.TryParse(id, out asGuid) == false)
{
@@ -264,7 +265,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
int id;
var parts = entity.Path.Split(Comma, StringSplitOptions.RemoveEmptyEntries);
- return parts.Length >= 2 && int.TryParse(parts[1], out id) ? id : 0;
+ return parts.Length >= 2 && int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out id) ? id : 0;
}
protected abstract ActionResult PerformGetMenuForNode(string id, FormCollection queryStrings);
@@ -275,7 +276,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
// try to parse id as an integer else use GetEntityFromId
// which will grok Guids, Udis, etc and let use obtain the id
- if (!int.TryParse(id, out var entityId))
+ if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var entityId))
{
var entity = GetEntityFromId(id);
if (entity == null)
@@ -544,7 +545,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
return new Tuple(idGuid, null);
}
- if (int.TryParse(id, out idInt))
+ if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out idInt))
{
return new Tuple(null, idInt);
}
@@ -576,7 +577,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
entity = _entityService.Get(idGuid, UmbracoObjectType);
}
- else if (int.TryParse(s, out var idInt))
+ else if (int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var idInt))
{
entity = _entityService.Get(idInt, UmbracoObjectType);
}
diff --git a/src/Umbraco.Web.BackOffice/Trees/ContentTypeTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ContentTypeTreeController.cs
index 2ba9e5f6c7..2be23f69e2 100644
--- a/src/Umbraco.Web.BackOffice/Trees/ContentTypeTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/ContentTypeTreeController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -54,13 +55,15 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected override ActionResult GetTreeNodes(string id, FormCollection queryStrings)
{
- var intId = id.TryConvertTo();
- if (intId == false) throw new InvalidOperationException("Id must be an integer");
+ if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
+ {
+ throw new InvalidOperationException("Id must be an integer");
+ }
var nodes = new TreeNodeCollection();
nodes.AddRange(
- _entityService.GetChildren(intId.Result, UmbracoObjectTypes.DocumentTypeContainer)
+ _entityService.GetChildren(intId, UmbracoObjectTypes.DocumentTypeContainer)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
@@ -75,7 +78,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
//if the request is for folders only then just return
if (queryStrings["foldersonly"].ToString().IsNullOrWhiteSpace() == false && queryStrings["foldersonly"] == "1") return nodes;
- var children = _entityService.GetChildren(intId.Result, UmbracoObjectTypes.DocumentType).ToArray();
+ var children = _entityService.GetChildren(intId, UmbracoObjectTypes.DocumentType).ToArray();
var contentTypes = _contentTypeService.GetAll(children.Select(c => c.Id).ToArray()).ToDictionary(c => c.Id);
nodes.AddRange(
children
@@ -125,7 +128,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var container = _entityService.Get(int.Parse(id), UmbracoObjectTypes.DocumentTypeContainer);
+ var container = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.DocumentTypeContainer);
if (container != null)
{
//set the default to create
@@ -147,7 +150,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
else
{
- var ct = _contentTypeService.Get(int.Parse(id));
+ var ct = _contentTypeService.Get(int.Parse(id, CultureInfo.InvariantCulture));
var parent = ct == null ? null : _contentTypeService.Get(ct.ParentId);
menu.Items.Add(LocalizedTextService, opensDialog: true);
diff --git a/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs
index bddf823c43..2a2c4bed0c 100644
--- a/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -42,14 +43,16 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected override ActionResult GetTreeNodes(string id, FormCollection queryStrings)
{
- var intId = id.TryConvertTo();
- if (intId == false) throw new InvalidOperationException("Id must be an integer");
+ if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
+ {
+ throw new InvalidOperationException("Id must be an integer");
+ }
var nodes = new TreeNodeCollection();
//Folders first
nodes.AddRange(
- _entityService.GetChildren(intId.Result, UmbracoObjectTypes.DataTypeContainer)
+ _entityService.GetChildren(intId, UmbracoObjectTypes.DataTypeContainer)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
@@ -67,7 +70,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
//System ListView nodes
var systemListViewDataTypeIds = GetNonDeletableSystemListViewDataTypeIds();
- var children = _entityService.GetChildren(intId.Result, UmbracoObjectTypes.DataType).ToArray();
+ var children = _entityService.GetChildren(intId, UmbracoObjectTypes.DataType).ToArray();
var dataTypes = Enumerable.ToDictionary(_dataTypeService.GetAll(children.Select(c => c.Id).ToArray()), dt => dt.Id);
nodes.AddRange(
@@ -134,7 +137,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var container = _entityService.Get(int.Parse(id), UmbracoObjectTypes.DataTypeContainer);
+ var container = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.DataTypeContainer);
if (container != null)
{
//set the default to create
@@ -158,7 +161,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
var nonDeletableSystemDataTypeIds = GetNonDeletableSystemDataTypeIds();
- if (nonDeletableSystemDataTypeIds.Contains(int.Parse(id)) == false)
+ if (nonDeletableSystemDataTypeIds.Contains(int.Parse(id, CultureInfo.InvariantCulture)) == false)
menu.Items.Add(LocalizedTextService, opensDialog: true);
menu.Items.Add(LocalizedTextService, hasSeparator: true, opensDialog: true);
diff --git a/src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs
index 0722a095b3..c61fabfa7b 100644
--- a/src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -69,9 +70,10 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
///
protected override ActionResult GetTreeNodes(string id, FormCollection queryStrings)
{
- var intId = id.TryConvertTo();
- if (intId == false)
+ if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
+ {
throw new InvalidOperationException("Id must be an integer");
+ }
var nodes = new TreeNodeCollection();
@@ -92,7 +94,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
else
{
// maybe we should use the guid as URL param to avoid the extra call for getting dictionary item
- var parentDictionary = _localizationService.GetDictionaryItemById(intId.Result);
+ var parentDictionary = _localizationService.GetDictionaryItemById(intId);
if (parentDictionary == null)
return nodes;
diff --git a/src/Umbraco.Web.BackOffice/Trees/MacrosTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/MacrosTreeController.cs
index c29518473d..d90a53c8e2 100644
--- a/src/Umbraco.Web.BackOffice/Trees/MacrosTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/MacrosTreeController.cs
@@ -1,3 +1,4 @@
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -79,7 +80,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var macro = _macroService.GetById(int.Parse(id));
+ var macro = _macroService.GetById(int.Parse(id, CultureInfo.InvariantCulture));
if (macro == null) return menu;
//add delete option for all macros
diff --git a/src/Umbraco.Web.BackOffice/Trees/MediaTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/MediaTreeController.cs
index 2ff354410c..a1a83bc5f3 100644
--- a/src/Umbraco.Web.BackOffice/Trees/MediaTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/MediaTreeController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -122,7 +123,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- if (int.TryParse(id, out var iid) == false)
+ if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var iid) == false)
{
return NotFound();
}
diff --git a/src/Umbraco.Web.BackOffice/Trees/MediaTypeTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/MediaTypeTreeController.cs
index 2cda5802b8..c19c9a800a 100644
--- a/src/Umbraco.Web.BackOffice/Trees/MediaTypeTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/MediaTypeTreeController.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -41,13 +42,15 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected override ActionResult GetTreeNodes(string id, FormCollection queryStrings)
{
- var intId = id.TryConvertTo();
- if (intId == false) throw new InvalidOperationException("Id must be an integer");
+ if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
+ {
+ throw new InvalidOperationException("Id must be an integer");
+ }
var nodes = new TreeNodeCollection();
nodes.AddRange(
- _entityService.GetChildren(intId.Result, UmbracoObjectTypes.MediaTypeContainer)
+ _entityService.GetChildren(intId, UmbracoObjectTypes.MediaTypeContainer)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
@@ -65,7 +68,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var mediaTypes = _mediaTypeService.GetAll();
nodes.AddRange(
- _entityService.GetChildren(intId.Result, UmbracoObjectTypes.MediaType)
+ _entityService.GetChildren(intId, UmbracoObjectTypes.MediaType)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
@@ -97,7 +100,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var container = _entityService.Get(int.Parse(id), UmbracoObjectTypes.MediaTypeContainer);
+ var container = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.MediaTypeContainer);
if (container != null)
{
// set the default to create
@@ -119,7 +122,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
else
{
- var ct = _mediaTypeService.Get(int.Parse(id));
+ var ct = _mediaTypeService.Get(int.Parse(id, CultureInfo.InvariantCulture));
var parent = ct == null ? null : _mediaTypeService.Get(ct.ParentId);
menu.Items.Add(LocalizedTextService, opensDialog: true);
diff --git a/src/Umbraco.Web.BackOffice/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/RelationTypeTreeController.cs
index 6da2298e03..22f96fa7c8 100644
--- a/src/Umbraco.Web.BackOffice/Trees/RelationTypeTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/RelationTypeTreeController.cs
@@ -1,3 +1,4 @@
+using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -51,7 +52,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var relationType = _relationService.GetRelationTypeById(int.Parse(id));
+ var relationType = _relationService.GetRelationTypeById(int.Parse(id, CultureInfo.InvariantCulture));
if (relationType == null) return menu;
if (relationType.IsSystemRelationType() == false)
diff --git a/src/Umbraco.Web.BackOffice/Trees/TemplatesTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/TemplatesTreeController.cs
index 4c91edbf45..e017f0e6d0 100644
--- a/src/Umbraco.Web.BackOffice/Trees/TemplatesTreeController.cs
+++ b/src/Umbraco.Web.BackOffice/Trees/TemplatesTreeController.cs
@@ -76,7 +76,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var found = id == Constants.System.RootString
? _fileService.GetTemplates(-1)
- : _fileService.GetTemplates(int.Parse(id));
+ : _fileService.GetTemplates(int.Parse(id, CultureInfo.InvariantCulture));
nodes.AddRange(found.Select(template => CreateTreeNode(
template.Id.ToString(CultureInfo.InvariantCulture),
@@ -115,7 +115,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
- var template = _fileService.GetTemplate(int.Parse(id));
+ var template = _fileService.GetTemplate(int.Parse(id, CultureInfo.InvariantCulture));
if (template == null) return menu;
var entity = FromTemplate(template);
diff --git a/src/Umbraco.Web.Common/Filters/UmbracoMemberAuthorizeFilter.cs b/src/Umbraco.Web.Common/Filters/UmbracoMemberAuthorizeFilter.cs
index b0a640b230..6cc81fd724 100644
--- a/src/Umbraco.Web.Common/Filters/UmbracoMemberAuthorizeFilter.cs
+++ b/src/Umbraco.Web.Common/Filters/UmbracoMemberAuthorizeFilter.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
@@ -71,7 +72,7 @@ namespace Umbraco.Cms.Web.Common.Filters
var members = new List();
foreach (var s in AllowMembers.Split(Core.Constants.CharArrays.Comma))
{
- if (int.TryParse(s, out var id))
+ if (int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var id))
{
members.Add(id);
}
diff --git a/src/Umbraco.Web.Common/Security/MemberManager.cs b/src/Umbraco.Web.Common/Security/MemberManager.cs
index f7d0c8e43e..9a0f26aff4 100644
--- a/src/Umbraco.Web.Common/Security/MemberManager.cs
+++ b/src/Umbraco.Web.Common/Security/MemberManager.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
@@ -82,7 +83,7 @@ namespace Umbraco.Cms.Web.Common.Security
return false;
}
- int memberId = int.Parse(currentMember.Id);
+ int memberId = int.Parse(currentMember.Id, CultureInfo.InvariantCulture);
username = currentMember.UserName;
// If types defined, check member is of one of those types
@@ -192,7 +193,7 @@ namespace Umbraco.Cms.Web.Common.Security
if (currentMember == null || !currentMember.IsApproved || currentMember.IsLockedOut)
{
return false;
- }
+ }
return await _publicAccessService.HasAccessAsync(
path,
@@ -231,7 +232,7 @@ namespace Umbraco.Cms.Web.Common.Security
async () => await getUserRolesAsync());
}
return result;
- }
+ }
public IPublishedContent AsPublishedMember(MemberIdentityUser user) => _store.GetPublishedMember(user);
}