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.Succeed(value); } @@ -301,7 +302,7 @@ namespace Umbraco.Extensions // Because decimal 100.01m will happily convert to integer 100, it // makes sense that string "100.01" *also* converts to integer 100. var input2 = NormalizeNumberDecimalSeparator(input); - return Attempt.If(decimal.TryParse(input2, out var value2), Convert.ToInt32(value2)); + return Attempt.If(decimal.TryParse(input2, out var value2), Convert.ToInt32(value2)); } if (target == typeof(long)) @@ -320,7 +321,7 @@ namespace Umbraco.Extensions if (target == typeof(bool)) { - if (bool.TryParse(input, out var value)) + if (bool.TryParse(input, out var value)) { return Attempt.Succeed(value); } @@ -337,11 +338,11 @@ namespace Umbraco.Extensions case TypeCode.Double: var input2 = NormalizeNumberDecimalSeparator(input); - return Attempt.If(double.TryParse(input2, out var valueD), valueD); + return Attempt.If(double.TryParse(input2, out var valueD), valueD); case TypeCode.Single: var input3 = NormalizeNumberDecimalSeparator(input); - return Attempt.If(float.TryParse(input3, out var valueF), valueF); + return Attempt.If(float.TryParse(input3, out var valueF), valueF); case TypeCode.Char: return Attempt.If(char.TryParse(input, out var valueC), valueC); @@ -353,13 +354,13 @@ namespace Umbraco.Extensions return Attempt.If(sbyte.TryParse(input, out var valueSb), valueSb); case TypeCode.UInt32: - return Attempt.If(uint.TryParse(input, out var valueU), valueU); + return Attempt.If(uint.TryParse(input, out var valueU), valueU); case TypeCode.UInt16: - return Attempt.If(ushort.TryParse(input, out var valueUs), valueUs); + return Attempt.If(ushort.TryParse(input, out var valueUs), valueUs); case TypeCode.UInt64: - return Attempt.If(ulong.TryParse(input, out var valueUl), valueUl); + return Attempt.If(ulong.TryParse(input, out var valueUl), valueUl); } } else if (target == typeof(Guid)) diff --git a/src/Umbraco.Core/Extensions/VersionExtensions.cs b/src/Umbraco.Core/Extensions/VersionExtensions.cs index 06451ce8a0..24326ef327 100644 --- a/src/Umbraco.Core/Extensions/VersionExtensions.cs +++ b/src/Umbraco.Core/Extensions/VersionExtensions.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using Umbraco.Cms.Core.Semver; namespace Umbraco.Extensions @@ -12,7 +13,7 @@ namespace Umbraco.Extensions public static Version GetVersion(this SemVersion semVersion, int maxParts = 4) { int build = 0; - int.TryParse(semVersion.Build, out build); + int.TryParse(semVersion.Build, NumberStyles.Integer, CultureInfo.InvariantCulture, out build); if (maxParts >= 4) { diff --git a/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs b/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs index 900c9b1b43..74465a6684 100644 --- a/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs +++ b/src/Umbraco.Core/Media/Exif/ExifBitConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text; namespace Umbraco.Cms.Core.Media.Exif @@ -65,12 +66,12 @@ namespace Umbraco.Cms.Core.Media.Exif // yyyy:MM:dd HH:mm:ss // This is the expected format though some cameras // can use single digits. See Issue 21. - return new DateTime(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]), int.Parse(parts[5])); + return new DateTime(int.Parse(parts[0], CultureInfo.InvariantCulture), int.Parse(parts[1], CultureInfo.InvariantCulture), int.Parse(parts[2], CultureInfo.InvariantCulture), int.Parse(parts[3], CultureInfo.InvariantCulture), int.Parse(parts[4], CultureInfo.InvariantCulture), int.Parse(parts[5], CultureInfo.InvariantCulture)); } else if (!hastime && parts.Length == 3) { // yyyy:MM:dd - return new DateTime(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])); + return new DateTime(int.Parse(parts[0], CultureInfo.InvariantCulture), int.Parse(parts[1], CultureInfo.InvariantCulture), int.Parse(parts[2], CultureInfo.InvariantCulture)); } else { diff --git a/src/Umbraco.Core/Media/Exif/MathEx.cs b/src/Umbraco.Core/Media/Exif/MathEx.cs index dfad9ae7de..5262aa18a8 100644 --- a/src/Umbraco.Core/Media/Exif/MathEx.cs +++ b/src/Umbraco.Core/Media/Exif/MathEx.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text; namespace Umbraco.Cms.Core.Media.Exif @@ -701,7 +702,7 @@ namespace Umbraco.Cms.Core.Media.Exif if (sa.Length == 1) { // Try to parse as int - if (int.TryParse(sa[0], out numerator)) + if (int.TryParse(sa[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out numerator)) { denominator = 1; } @@ -714,8 +715,8 @@ namespace Umbraco.Cms.Core.Media.Exif } else if (sa.Length == 2) { - numerator = int.Parse(sa[0]); - denominator = int.Parse(sa[1]); + numerator = int.Parse(sa[0], CultureInfo.InvariantCulture); + denominator = int.Parse(sa[1], CultureInfo.InvariantCulture); } else throw new FormatException("The input string must be formatted as n/d where n and d are integers"); @@ -1329,7 +1330,7 @@ namespace Umbraco.Cms.Core.Media.Exif if (sa.Length == 1) { // Try to parse as uint - if (uint.TryParse(sa[0], out numerator)) + if (uint.TryParse(sa[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out numerator)) { denominator = 1; } @@ -1342,8 +1343,8 @@ namespace Umbraco.Cms.Core.Media.Exif } else if (sa.Length == 2) { - numerator = uint.Parse(sa[0]); - denominator = uint.Parse(sa[1]); + numerator = uint.Parse(sa[0], CultureInfo.InvariantCulture); + denominator = uint.Parse(sa[1], CultureInfo.InvariantCulture); } else throw new FormatException("The input string must be formatted as n/d where n and d are integers"); diff --git a/src/Umbraco.Core/Media/Exif/SvgFile.cs b/src/Umbraco.Core/Media/Exif/SvgFile.cs index 00516eecb8..b83aebe1fb 100644 --- a/src/Umbraco.Core/Media/Exif/SvgFile.cs +++ b/src/Umbraco.Core/Media/Exif/SvgFile.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Globalization; +using System.IO; using System.Linq; using System.Xml.Linq; @@ -16,9 +17,9 @@ namespace Umbraco.Cms.Core.Media.Exif var height = document.Root?.Attributes().Where(x => x.Name == "height").Select(x => x.Value).FirstOrDefault(); Properties.Add(new ExifSInt(ExifTag.PixelYDimension, - height == null ? Constants.Conventions.Media.DefaultSize : int.Parse(height))); + height == null ? Constants.Conventions.Media.DefaultSize : int.Parse(height, CultureInfo.InvariantCulture))); Properties.Add(new ExifSInt(ExifTag.PixelXDimension, - width == null ? Constants.Conventions.Media.DefaultSize : int.Parse(width))); + width == null ? Constants.Conventions.Media.DefaultSize : int.Parse(width, CultureInfo.InvariantCulture))); Format = ImageFileFormat.SVG; } diff --git a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs index 7449a6f778..d3269c2c0b 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -601,7 +602,7 @@ namespace Umbraco.Cms.Core.Models.Mapping return Enumerable.Empty(); var aliases = new List(); - var ancestorIds = parent.Path.Split(Constants.CharArrays.Comma).Select(int.Parse); + var ancestorIds = parent.Path.Split(Constants.CharArrays.Comma).Select(s => int.Parse(s, CultureInfo.InvariantCulture)); // loop through all content types and return ordered aliases of ancestors var allContentTypes = _contentTypeService.GetAll().ToArray(); foreach (var ancestorId in ancestorIds) diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index a24890d5f2..79f9aba722 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; @@ -294,7 +295,7 @@ namespace Umbraco.Cms.Core.Packaging var dataTypes = new XElement("DataTypes"); foreach (var dtId in definition.DataTypes) { - if (!int.TryParse(dtId, out var outInt)) + if (!int.TryParse(dtId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) continue; var dataType = _dataTypeService.GetDataType(outInt); if (dataType == null) @@ -309,7 +310,7 @@ namespace Umbraco.Cms.Core.Packaging var languages = new XElement("Languages"); foreach (var langId in definition.Languages) { - if (!int.TryParse(langId, out var outInt)) + if (!int.TryParse(langId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) continue; var lang = _languageService.GetLanguageById(outInt); if (lang == null) @@ -326,7 +327,7 @@ namespace Umbraco.Cms.Core.Packaging foreach (var dictionaryId in definition.DictionaryItems) { - if (!int.TryParse(dictionaryId, out var outInt)) + if (!int.TryParse(dictionaryId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) { continue; } @@ -397,7 +398,7 @@ namespace Umbraco.Cms.Core.Packaging var macros = new XElement("Macros"); foreach (var macroId in definition.Macros) { - if (!int.TryParse(macroId, out int outInt)) + if (!int.TryParse(macroId, NumberStyles.Integer, CultureInfo.InvariantCulture, out int outInt)) { continue; } @@ -477,7 +478,7 @@ namespace Umbraco.Cms.Core.Packaging var templatesXml = new XElement("Templates"); foreach (var templateId in definition.Templates) { - if (!int.TryParse(templateId, out var outInt)) + if (!int.TryParse(templateId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) continue; var template = _fileService.GetTemplate(outInt); if (template == null) @@ -520,7 +521,7 @@ namespace Umbraco.Cms.Core.Packaging var docTypesXml = new XElement("DocumentTypes"); foreach (var dtId in definition.DocumentTypes) { - if (!int.TryParse(dtId, out var outInt)) + if (!int.TryParse(dtId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) continue; var contentType = _contentTypeService.Get(outInt); if (contentType == null) @@ -539,7 +540,7 @@ namespace Umbraco.Cms.Core.Packaging var mediaTypesXml = new XElement("MediaTypes"); foreach (var mediaTypeId in definition.MediaTypes) { - if (!int.TryParse(mediaTypeId, out var outInt)) + if (!int.TryParse(mediaTypeId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) continue; var mediaType = _mediaTypeService.Get(outInt); if (mediaType == null) @@ -555,7 +556,7 @@ namespace Umbraco.Cms.Core.Packaging private void PackageDocumentsAndTags(PackageDefinition definition, XContainer root) { //Documents and tags - if (string.IsNullOrEmpty(definition.ContentNodeId) == false && int.TryParse(definition.ContentNodeId, out var contentNodeId)) + if (string.IsNullOrEmpty(definition.ContentNodeId) == false && int.TryParse(definition.ContentNodeId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var contentNodeId)) { if (contentNodeId > 0) { diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs index 637039faa9..c873b29b98 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters case ValueTypes.Integer: if (source is int sourceInt) return sourceInt; if (source is string sourceIntString) - return int.TryParse(sourceIntString, out var i) ? i : 0; + return int.TryParse(sourceIntString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : 0; return 0; case ValueTypes.Bigint: if (source is string sourceLongString) diff --git a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs index 13a3d8c973..d8093aed1b 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs @@ -1,3 +1,4 @@ +using System.Globalization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; @@ -60,7 +61,7 @@ namespace Umbraco.Cms.Core.Routing { var noSlashPath = path.Substring(1); - if (int.TryParse(noSlashPath, out nodeId) == false) + if (int.TryParse(noSlashPath, NumberStyles.Integer, CultureInfo.InvariantCulture, out nodeId) == false) { nodeId = -1; } diff --git a/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs b/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs index b5b80d7b9e..7a71cfc5cd 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByPageIdQuery.cs @@ -1,3 +1,4 @@ +using System.Globalization; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Web; using Umbraco.Extensions; @@ -32,7 +33,7 @@ namespace Umbraco.Cms.Core.Routing { return false; } - if (int.TryParse(_requestAccessor.GetRequestValue("umbPageID"), out int pageId)) + if (int.TryParse(_requestAccessor.GetRequestValue("umbPageID"), NumberStyles.Integer, CultureInfo.InvariantCulture, out int pageId)) { IPublishedContent doc = umbracoContext.Content.GetById(pageId); diff --git a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs index 4e5d854250..16248854e5 100644 --- a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; @@ -56,7 +57,7 @@ namespace Umbraco.Cms.Core.Routing var path = pos == 0 ? route : route.Substring(pos); var domainUri = pos == 0 ? null - : DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, int.Parse(route.Substring(0, pos)), current, culture); + : DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current, culture); // assemble the URL from domainUri (maybe null) and path var url = AssembleUrl(domainUri, path, current, mode).ToString(); diff --git a/src/Umbraco.Core/Routing/DomainUtilities.cs b/src/Umbraco.Core/Routing/DomainUtilities.cs index 035e57c43a..2e36e8c0ef 100644 --- a/src/Umbraco.Core/Routing/DomainUtilities.cs +++ b/src/Umbraco.Core/Routing/DomainUtilities.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Web; @@ -47,7 +48,7 @@ namespace Umbraco.Cms.Core.Routing var pos = route.IndexOf('/'); var domain = pos == 0 ? null - : DomainForNode(umbracoContext.Domains, siteDomainMapper, int.Parse(route.Substring(0, pos)), current); + : DomainForNode(umbracoContext.Domains, siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current); var rootContentId = domain?.ContentId ?? -1; var wcDomain = FindWildcardDomainInPath(umbracoContext.Domains.GetAll(true), contentPath, rootContentId); @@ -329,7 +330,7 @@ namespace Umbraco.Cms.Core.Routing return path.Split(Constants.CharArrays.Comma) .Reverse() - .Select(int.Parse) + .Select(s => int.Parse(s, CultureInfo.InvariantCulture)) .TakeWhile(id => id != stopNodeId) .Select(id => domains.FirstOrDefault(d => d.ContentId == id && d.IsWildcard == false)) .SkipWhile(domain => domain == null) @@ -350,7 +351,7 @@ namespace Umbraco.Cms.Core.Routing return path.Split(Constants.CharArrays.Comma) .Reverse() - .Select(int.Parse) + .Select(s => int.Parse(s, CultureInfo.InvariantCulture)) .TakeWhile(id => id != stopNodeId) .Select(id => domains.FirstOrDefault(d => d.ContentId == id && d.IsWildcard)) .FirstOrDefault(domain => domain != null); diff --git a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs index a92548ea18..a75fd3dee9 100644 --- a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs +++ b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Text.RegularExpressions; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Web; @@ -114,7 +115,7 @@ namespace Umbraco.Cms.Core.Templates yield return (null, guidUdi, tag.Value); } - if (int.TryParse(id, out var intId)) + if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId)) { yield return (intId, null, tag.Value); } diff --git a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs index e92aa8e147..5d72221391 100644 --- a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs +++ b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace Umbraco.Cms.Core.Xml @@ -49,9 +50,9 @@ namespace Umbraco.Cms.Core.Xml foreach (var i in path) { int idAsInt; - if (int.TryParse(i, out idAsInt)) + if (int.TryParse(i, NumberStyles.Integer, CultureInfo.InvariantCulture, out idAsInt)) { - var exists = publishedContentExists(int.Parse(i)); + var exists = publishedContentExists(int.Parse(i, CultureInfo.InvariantCulture)); if (exists) return idAsInt; } diff --git a/src/Umbraco.Core/Xml/XPath/NavigableNavigator.cs b/src/Umbraco.Core/Xml/XPath/NavigableNavigator.cs index 68dfb9bb67..5ebc575243 100644 --- a/src/Umbraco.Core/Xml/XPath/NavigableNavigator.cs +++ b/src/Umbraco.Core/Xml/XPath/NavigableNavigator.cs @@ -300,7 +300,7 @@ namespace Umbraco.Cms.Core.Xml.XPath public XPathNavigator CloneWithNewRoot(string id, int maxDepth = int.MaxValue) { int i; - if (int.TryParse(id, out i) == false) + if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out i) == false) throw new ArgumentException("Not a valid identifier.", nameof(id)); return CloneWithNewRoot(id); } @@ -679,7 +679,7 @@ namespace Umbraco.Cms.Core.Xml.XPath var navRootId = state.Content.Id; int contentId; - if (int.TryParse(id, out contentId)) + if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out contentId)) { if (contentId == navRootId) { diff --git a/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs b/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs index 27fdf1f2f7..5e2b66c720 100644 --- a/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs +++ b/src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -335,7 +336,7 @@ namespace Umbraco.Cms.Infrastructure.Examine UdiParser.TryParse(searchFrom, true, out var udi); searchFrom = udi == null ? searchFrom : entityService.GetId(udi).Result.ToString(); - var entityPath = int.TryParse(searchFrom, out var searchFromId) && searchFromId > 0 + var entityPath = int.TryParse(searchFrom, NumberStyles.Integer, CultureInfo.InvariantCulture, out var searchFromId) && searchFromId > 0 ? entityService.GetAllPaths(objectType, searchFromId).FirstOrDefault() : null; if (entityPath != null) diff --git a/src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs b/src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs index df0f074ea3..4222ac800e 100644 --- a/src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs +++ b/src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs @@ -1,6 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. +using System.Globalization; using System.Linq; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; @@ -72,7 +73,7 @@ namespace Umbraco.Cms.Core.Events { var originalPath = item.OriginalPath.ToDelimitedList(); var originalParentId = originalPath.Count > 2 - ? int.Parse(originalPath[originalPath.Count - 2]) + ? int.Parse(originalPath[originalPath.Count - 2], CultureInfo.InvariantCulture) : Constants.System.Root; //before we can create this relation, we need to ensure that the original parent still exists which @@ -130,7 +131,7 @@ namespace Umbraco.Cms.Core.Events { var originalPath = item.OriginalPath.ToDelimitedList(); var originalParentId = originalPath.Count > 2 - ? int.Parse(originalPath[originalPath.Count - 2]) + ? int.Parse(originalPath[originalPath.Count - 2], CultureInfo.InvariantCulture) : Constants.System.Root; //before we can create this relation, we need to ensure that the original parent still exists which //may not be the case if the encompassing transaction also deleted it when this item was moved to the bin diff --git a/src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs b/src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs index d0f65fe6a4..b2b025b5a6 100644 --- a/src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs +++ b/src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using Examine; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; @@ -32,7 +33,7 @@ namespace Umbraco.Extensions foreach (var result in results) { - if (int.TryParse(result.Id, out var contentId) && + if (int.TryParse(result.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var contentId) && cache.GetById(contentId) is IPublishedContent content) { publishedSearchResults.Add(new PublishedSearchResult(content, result.Score)); @@ -62,7 +63,7 @@ namespace Umbraco.Extensions foreach (var result in results) { - if (int.TryParse(result.Id, out var contentId) && + if (int.TryParse(result.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var contentId) && result.Values.TryGetValue(ExamineFieldNames.CategoryFieldName, out var indexType)) { IPublishedContent content; diff --git a/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs b/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs index 5afe010b82..4fbbb35a6d 100644 --- a/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs +++ b/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs @@ -198,7 +198,7 @@ namespace Umbraco.Cms.Infrastructure.Examine foreach (ISearchResult item in paged) { - if (int.TryParse(item.Id, out int contentId)) + if (int.TryParse(item.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out int contentId)) { DeleteIndexForEntity(contentId, false); } @@ -411,7 +411,7 @@ namespace Umbraco.Cms.Infrastructure.Examine else { Execute(_examineUmbracoIndexingHandler, _ids, _keepIfUnpublished); - } + } } public static void Execute(ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, int id, bool keepIfUnpublished) diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index fdcef20943..73b9d702b7 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -73,11 +73,11 @@ namespace Umbraco.Cms.Infrastructure.Install.InstallSteps _userService.Save(admin); - var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserId.ToString()); + var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserIdAsString); if (membershipUser == null) { throw new InvalidOperationException( - $"No user found in membership provider with id of {Constants.Security.SuperUserId}."); + $"No user found in membership provider with id of {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.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs index 4e277262a7..70f5b6f0bf 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/ConvertRelatedLinksToMultiUrlPicker.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Runtime.Serialization; using Newtonsoft.Json; @@ -68,7 +69,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0 if (linkIsUdi == false) { // oh no.. probably an integer, yikes! - if (int.TryParse(relatedLink.Link, out var intId)) + if (int.TryParse(relatedLink.Link, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId)) { var sqlNodeData = Sql() .Select() diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs index 01cd171b6b..0b9bb4519c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/ListViewPreValueMigrator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using Newtonsoft.Json; using Umbraco.Extensions; @@ -18,7 +19,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes protected override object GetPreValueValue(PreValueDto preValue) { if (preValue.Alias == "pageSize") - return int.TryParse(preValue.Value, out var i) ? (int?)i : null; + return int.TryParse(preValue.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? (int?)i : null; return preValue.Value.DetectIsJson() ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs index aba3e3f407..98eac62f15 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/NestedContentPreValueMigrator.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Globalization; +using Newtonsoft.Json; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes @@ -25,7 +26,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0.DataTypes if (preValue.Alias == "minItems" || preValue.Alias == "maxItems") - return int.TryParse(preValue.Value, out var i) ? (int?)i : null; + return int.TryParse(preValue.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? (int?)i : null; return preValue.Value.DetectIsJson() ? JsonConvert.DeserializeObject(preValue.Value) : preValue.Value; } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs index b5e50d2248..f24cfc1142 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -35,7 +36,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0 var splitVals = val.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries); var intVals = splitVals - .Select(x => int.TryParse(x, out var i) ? i : int.MinValue) + .Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : int.MinValue) .Where(x => x != int.MinValue) .ToArray(); diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs index cea0fbdd23..3cbc7357e5 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/UpdatePickerIntegerValuesToUdi.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -33,7 +34,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0 { var config = JsonConvert.DeserializeObject(datatype.Configuration); var startNodeId = config.Value("startNodeId"); - if (!startNodeId.IsNullOrWhiteSpace() && int.TryParse(startNodeId, out var intStartNode)) + if (!startNodeId.IsNullOrWhiteSpace() && int.TryParse(startNodeId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intStartNode)) { var guid = intStartNode <= 0 ? null @@ -65,7 +66,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0 var objectType = startNodeConfig.Value("type"); if (!objectType.IsNullOrWhiteSpace() && !startNodeId.IsNullOrWhiteSpace() - && int.TryParse(startNodeId, out var intStartNode)) + && int.TryParse(startNodeId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intStartNode)) { var guid = intStartNode <= 0 ? null diff --git a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs index e96e96f521..2b52a93741 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using Examine; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models.ContentEditing; @@ -224,7 +225,7 @@ namespace Umbraco.Cms.Core.Models.Mapping if (source.Values.ContainsKey("parentID")) { - if (int.TryParse(source.Values["parentID"], out var parentId)) + if (int.TryParse(source.Values["parentID"], NumberStyles.Integer, CultureInfo.InvariantCulture,out var parentId)) { target.ParentId = parentId; } diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 05ceef6697..8f016ada7f 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Net; using System.Text; @@ -323,8 +324,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging parentId, contentType, key, - int.Parse(level), - int.Parse(sortOrder), + int.Parse(level, CultureInfo.InvariantCulture), + int.Parse(sortOrder, CultureInfo.InvariantCulture), template?.Id); // Handle culture specific node names @@ -837,7 +838,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging propertyGroup.Type = type; } - if (int.TryParse(propertyGroupElement.Element("SortOrder")?.Value, out var sortOrder)) + if (int.TryParse(propertyGroupElement.Element("SortOrder")?.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var sortOrder)) { // Override the sort order with the imported value propertyGroup.SortOrder = sortOrder; @@ -901,7 +902,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging var sortOrderElement = property.Element("SortOrder"); if (sortOrderElement != null) { - int.TryParse(sortOrderElement.Value, out sortOrder); + int.TryParse(sortOrderElement.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out sortOrder); } var propertyType = new PropertyType(_shortStringHelper, dataTypeDefinition, property.Element("Alias").Value) @@ -1323,7 +1324,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging var cacheDuration = 0; if (cacheDurationElement != null && string.IsNullOrEmpty((string)cacheDurationElement) == false) { - cacheDuration = int.Parse(cacheDurationElement.Value); + cacheDuration = int.Parse(cacheDurationElement.Value, CultureInfo.InvariantCulture); } var cacheByMemberElement = macroElement.Element("cacheByMember"); var cacheByMember = false; @@ -1364,7 +1365,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging XAttribute sortOrderAttribute = property.Attribute("sortOrder"); if (sortOrderAttribute != null) { - sortOrder = int.Parse(sortOrderAttribute.Value); + sortOrder = int.Parse(sortOrderAttribute.Value, CultureInfo.InvariantCulture); } if (macro.Properties.Values.Any(x => string.Equals(x.Alias, propertyAlias, StringComparison.OrdinalIgnoreCase))) diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/ExternalLoginFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/ExternalLoginFactory.cs index 58819f306a..82bbb4a40a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/ExternalLoginFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/ExternalLoginFactory.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Infrastructure.Persistence.Dtos; @@ -8,7 +9,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories { public static IIdentityUserToken BuildEntity(ExternalLoginTokenDto dto) { - var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(), dto.CreateDate); + var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate); // reset dirty initial properties (U4-1946) entity.ResetDirtyProperties(false); @@ -17,7 +18,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories public static IIdentityUserLogin BuildEntity(ExternalLoginDto dto) { - var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(), dto.CreateDate) + var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate) { UserData = dto.UserData }; @@ -35,7 +36,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories CreateDate = entity.CreateDate, LoginProvider = entity.LoginProvider, ProviderKey = entity.ProviderKey, - UserId = int.Parse(entity.UserId), // TODO: This is temp until we change the ext logins to use GUIDs + UserId = int.Parse(entity.UserId, CultureInfo.InvariantCulture), // TODO: This is temp until we change the ext logins to use GUIDs UserData = entity.UserData }; diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/MacroFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/MacroFactory.cs index 960b809c74..7f73abacaa 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/MacroFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/MacroFactory.cs @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories }; if (entity.HasIdentity) - dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture)); + dto.Id = entity.Id; return dto; } diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/PropertyFactory.cs index 730c24f2f2..8df6d654b0 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/PropertyFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; @@ -53,7 +54,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories { dto.IntegerValue = value != null && string.IsNullOrEmpty(value.ToString()) ? 0 : Convert.ToInt32(value); } - else if (value != null && string.IsNullOrWhiteSpace(value.ToString()) == false && int.TryParse(value.ToString(), out var val)) + else if (value != null && string.IsNullOrWhiteSpace(value.ToString()) == false && int.TryParse(value.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var val)) { dto.IntegerValue = val; } diff --git a/src/Umbraco.Infrastructure/Persistence/FaultHandling/ThrottlingCondition.cs b/src/Umbraco.Infrastructure/Persistence/FaultHandling/ThrottlingCondition.cs index 9905a35696..9155937fe0 100644 --- a/src/Umbraco.Infrastructure/Persistence/FaultHandling/ThrottlingCondition.cs +++ b/src/Umbraco.Infrastructure/Persistence/FaultHandling/ThrottlingCondition.cs @@ -263,7 +263,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.FaultHandling var match = sqlErrorCodeRegEx.Match(error.Message); int reasonCode; - if (match.Success && int.TryParse(match.Groups[1].Value, out reasonCode)) + if (match.Success && int.TryParse(match.Groups[1].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out reasonCode)) { return FromReasonCode(reasonCode); } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index c72e11f595..239f0a89ed 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using Microsoft.Extensions.Logging; @@ -532,7 +533,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement currentParentIds.Add(node.NodeId); // paths parts without the roots - var pathParts = node.Path.Split(Constants.CharArrays.Comma).Where(x => !rootIds.Contains(int.Parse(x))).ToArray(); + var pathParts = node.Path.Split(Constants.CharArrays.Comma).Where(x => !rootIds.Contains(int.Parse(x, CultureInfo.InvariantCulture))).ToArray(); if (!prevParentIds.Contains(node.ParentId)) { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index f9e8316f70..d93c2c8322 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -1344,7 +1344,7 @@ WHERE cmsContentType." + aliasColumn + @" LIKE @pattern", /// public bool HasContainerInPath(string contentPath) { - var ids = contentPath.Split(Constants.CharArrays.Comma).Select(int.Parse).ToArray(); + var ids = contentPath.Split(Constants.CharArrays.Comma).Select(s => int.Parse(s, CultureInfo.InvariantCulture)).ToArray(); return HasContainerInPath(ids); } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs index 0353106e17..1ed8404f78 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.Extensions.Logging; using NPoco; @@ -941,7 +942,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement if (content.ParentId == -1) return content.Published; - var ids = content.Path.Split(Constants.CharArrays.Comma).Skip(1).Select(int.Parse); + var ids = content.Path.Split(Constants.CharArrays.Comma).Skip(1).Select(s => int.Parse(s, CultureInfo.InvariantCulture)); var sql = SqlContext.Sql() .SelectCount(x => x.NodeId) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimilarNodeName.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimilarNodeName.cs index 8dc8a7783d..116ec356b7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimilarNodeName.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/SimilarNodeName.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using Umbraco.Extensions; @@ -188,7 +189,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { var match = matches[0]; Text = match.Groups[1].Value; - int number = int.TryParse(match.Groups[2].Value, out number) ? number : 0; + int number = int.TryParse(match.Groups[2].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out number) ? number : 0; Suffix = (uint?)(number); return; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index 82b1305fe4..4c85277781 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -2,6 +2,7 @@ // See LICENSE for more details. using System; +using System.Globalization; using System.Linq; using System.Text; using HtmlAgilityPack; @@ -110,7 +111,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters foreach (var img in imgNodes) { var nodeId = img.GetAttributeValue("rel", string.Empty); - if (int.TryParse(nodeId, out _)) + if (int.TryParse(nodeId, NumberStyles.Integer, CultureInfo.InvariantCulture, out _)) { img.Attributes.Remove("rel"); modified = true; diff --git a/src/Umbraco.Infrastructure/PublishedContentQuery.cs b/src/Umbraco.Infrastructure/PublishedContentQuery.cs index 14298cbb4e..946f501b1f 100644 --- a/src/Umbraco.Infrastructure/PublishedContentQuery.cs +++ b/src/Umbraco.Infrastructure/PublishedContentQuery.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Xml.XPath; using Examine; @@ -43,7 +44,7 @@ namespace Umbraco.Cms.Infrastructure switch (id) { case string s: - return int.TryParse(s, out intId); + return int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out intId); case int i: intId = i; diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs index e3ddc69e6f..ebd12719e1 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Identity; using Umbraco.Cms.Core.Configuration.Models; @@ -157,6 +158,6 @@ namespace Umbraco.Cms.Core.Security Roles = roles; } - private static string UserIdToString(int userId) => string.Intern(userId.ToString()); + private static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture)); } } diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs index deb85ff496..0930b510f3 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Globalization; using System.Linq; using System.Security.Claims; using System.Threading; @@ -133,15 +134,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)) { throw new InvalidOperationException("The user id must be an integer to work with the Umbraco"); } using (IScope scope = _scopeProvider.CreateScope()) { - IUser found = _userService.GetUserById(asInt.Result); + IUser found = _userService.GetUserById(asInt); if (found != null) { // we have to remember whether Logins property is dirty, since the UpdateMemberProperties will reset it. @@ -441,7 +441,7 @@ namespace Umbraco.Cms.Core.Security if (identityUser.IsPropertyDirty(nameof(BackOfficeIdentityUser.InviteDateUtc)) || (user.InvitedDate?.ToUniversalTime() != identityUser.InviteDateUtc)) { - anythingChanged = true; + anythingChanged = true; user.InvitedDate = identityUser.InviteDateUtc?.ToLocalTime(); } diff --git a/src/Umbraco.Infrastructure/Security/MemberIdentityUser.cs b/src/Umbraco.Infrastructure/Security/MemberIdentityUser.cs index 724eb77030..9e29316056 100644 --- a/src/Umbraco.Infrastructure/Security/MemberIdentityUser.cs +++ b/src/Umbraco.Infrastructure/Security/MemberIdentityUser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Extensions; @@ -11,7 +12,7 @@ namespace Umbraco.Cms.Core.Security /// 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); }