Skip to content

Commit 452097d

Browse files
authored
Fixed issue with Paths-integers being converted using local culture. (#11180)
* Fixed issue with Paths-integers being converted using local culture. * Align with the old implementation * Use int.TryParse insteaad of TryConvertTo when we do not want culture specific parsing * More fixes for cultures and fixed wrong test. Users should be part of all groups to have access * Fix casing for requested file * Force tests to not use NLS * try force tests to not use NLS * try force tests to not use NLS * Force tests on windows to run ICU * More fixes for invariant int parsing * Change key on actions/emptyRecycleBin, so the casing aligns with the view file, that is named emptyrecyclebin.html * Fixed casing issue * use Attempt to align with other code
1 parent 9367572 commit 452097d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+173
-261
lines changed

src/Umbraco.Core/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ static StringExtensions()
4242
public static int[] GetIdsFromPathReversed(this string path)
4343
{
4444
var nodeIds = path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
45-
.Select(x => x.TryConvertTo<int>())
45+
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var output) ? Attempt<int>.Succeed(output) : Attempt<int>.Fail())
4646
.Where(x => x.Success)
47-
.Select(x => x.Result)
47+
.Select(x=>x.Result)
4848
.Reverse()
4949
.ToArray();
5050
return nodeIds;

src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ private IEnumerable<EditorNavigation> CreateUserEditorNavigation()
425425

426426
private static int GetIntId(object id)
427427
{
428+
if (id is string strId && int.TryParse(strId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt))
429+
{
430+
return asInt;
431+
}
428432
var result = id.TryConvertTo<int>();
429433
if (result.Success == false)
430434
{

src/Umbraco.Core/Models/UserExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ private static bool StartsWithPath(string test, string path)
219219

220220
private static string GetBinPath(UmbracoObjectTypes objectType)
221221
{
222-
var binPath = Constants.System.Root + ",";
222+
var binPath = Constants.System.RootString + ",";
223223
switch (objectType)
224224
{
225225
case UmbracoObjectTypes.Document:
226-
binPath += Constants.System.RecycleBinContent;
226+
binPath += Constants.System.RecycleBinContentString;
227227
break;
228228
case UmbracoObjectTypes.Media:
229-
binPath += Constants.System.RecycleBinMedia;
229+
binPath += Constants.System.RecycleBinMediaString;
230230
break;
231231
default:
232232
throw new ArgumentOutOfRangeException(nameof(objectType));

src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
3232
{
3333
if (source == null) return null;
3434

35+
36+
if(source is not string)
37+
{
38+
var attemptConvertInt = source.TryConvertTo<int>();
39+
if (attemptConvertInt.Success)
40+
return attemptConvertInt.Result;
41+
}
3542
//Don't attempt to convert to int for UDI
36-
if(!(source is string) || source is string strSource && !string.IsNullOrWhiteSpace(strSource) && !strSource.StartsWith("umb"))
43+
if( source is string strSource
44+
&& !string.IsNullOrWhiteSpace(strSource)
45+
&& !strSource.StartsWith("umb")
46+
&& int.TryParse(strSource, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
3747
{
38-
var attemptConvertInt = source.TryConvertTo<int>();
39-
if (attemptConvertInt.Success)
40-
return attemptConvertInt.Result;
48+
return intValue;
4149
}
4250

4351
var attemptConvertUdi = source.TryConvertTo<Udi>();

src/Umbraco.Core/Security/ContentPermissions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ public static bool HasPathAccess(string path, int[] startNodeIds, int recycleBin
236236

237237
// only users with root access have access to the recycle bin,
238238
// if the above check didn't pass then access is denied
239-
if (formattedPath.Contains(string.Concat(",", recycleBinId, ",")))
239+
if (formattedPath.Contains(string.Concat(",", recycleBinId.ToString(CultureInfo.InvariantCulture), ",")))
240240
return false;
241241

242242
// check for a start node in the path
243-
return startNodeIds.Any(x => formattedPath.Contains(string.Concat(",", x, ",")));
243+
return startNodeIds.Any(x => formattedPath.Contains(string.Concat(",", x.ToString(CultureInfo.InvariantCulture), ",")));
244244
}
245245

246246
public static bool IsInBranchOfStartNode(string path, int[] startNodeIds, string[] startNodePaths, out bool hasPathAccess)

src/Umbraco.Core/Services/UserServiceExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using Umbraco.Cms.Core;
56
using Umbraco.Cms.Core.Models.Membership;
@@ -12,9 +13,9 @@ public static class UserServiceExtensions
1213
public static EntityPermission GetPermissions(this IUserService userService, IUser user, string path)
1314
{
1415
var ids = path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
15-
.Select(x => x.TryConvertTo<int>())
16+
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? Attempt<int>.Succeed(value) : Attempt<int>.Fail())
1617
.Where(x => x.Success)
17-
.Select(x => x.Result)
18+
.Select(x=>x.Result)
1819
.ToArray();
1920
if (ids.Length == 0) throw new InvalidOperationException("The path: " + path + " could not be parsed into an array of integers or the path was empty");
2021

src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -382,91 +382,5 @@ private void AppendPath(StringBuilder sb, string path, bool includeThisNode)
382382
sb.Append(path);
383383
sb.Append("\\,*");
384384
}
385-
386-
// TODO: When/Where is this used?
387-
388-
/// <summary>
389-
/// Returns a collection of entities for media based on search results
390-
/// </summary>
391-
/// <param name="results"></param>
392-
/// <returns></returns>
393-
private IEnumerable<SearchResultEntity> MemberFromSearchResults(IEnumerable<ISearchResult> results)
394-
{
395-
//add additional data
396-
foreach (var result in results)
397-
{
398-
var m = _umbracoMapper.Map<SearchResultEntity>(result);
399-
400-
//if no icon could be mapped, it will be set to document, so change it to picture
401-
if (m.Icon == Constants.Icons.DefaultIcon)
402-
{
403-
m.Icon = Constants.Icons.Member;
404-
}
405-
406-
if (result.Values.ContainsKey("email") && result.Values["email"] != null)
407-
{
408-
m.AdditionalData["Email"] = result.Values["email"];
409-
}
410-
if (result.Values.ContainsKey(UmbracoExamineFieldNames.NodeKeyFieldName) && result.Values[UmbracoExamineFieldNames.NodeKeyFieldName] != null)
411-
{
412-
if (Guid.TryParse(result.Values[UmbracoExamineFieldNames.NodeKeyFieldName], out var key))
413-
{
414-
m.Key = key;
415-
}
416-
}
417-
418-
yield return m;
419-
}
420-
}
421-
422-
// TODO: When/Where is this used?
423-
424-
/// <summary>
425-
/// Returns a collection of entities for media based on search results
426-
/// </summary>
427-
/// <param name="results"></param>
428-
/// <returns></returns>
429-
private IEnumerable<SearchResultEntity> MediaFromSearchResults(IEnumerable<ISearchResult> results)
430-
=> _umbracoMapper.Map<IEnumerable<SearchResultEntity>>(results);
431-
432-
// TODO: When/Where is this used?
433-
434-
/// <summary>
435-
/// Returns a collection of entities for content based on search results
436-
/// </summary>
437-
/// <param name="results"></param>
438-
/// <returns></returns>
439-
private IEnumerable<SearchResultEntity> ContentFromSearchResults(IEnumerable<ISearchResult> results, string culture = null)
440-
{
441-
var defaultLang = _languageService.GetDefaultLanguageIsoCode();
442-
foreach (var result in results)
443-
{
444-
var entity = _umbracoMapper.Map<SearchResultEntity>(result, context =>
445-
{
446-
if (culture != null)
447-
{
448-
context.SetCulture(culture);
449-
}
450-
}
451-
);
452-
453-
var intId = entity.Id.TryConvertTo<int>();
454-
if (intId.Success)
455-
{
456-
//if it varies by culture, return the default language URL
457-
if (result.Values.TryGetValue(UmbracoExamineFieldNames.VariesByCultureFieldName, out var varies) && varies == "y")
458-
{
459-
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId.Result, culture: culture ?? defaultLang);
460-
}
461-
else
462-
{
463-
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId.Result);
464-
}
465-
}
466-
467-
yield return entity;
468-
}
469-
}
470-
471385
}
472386
}

src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Linq;
34
using Examine;
45
using Umbraco.Cms.Core.Scoping;
@@ -30,7 +31,7 @@ public bool ValidatePath(string path, string category)
3031
{
3132
// we cannot return FAILED here because we need the value set to get into the indexer and then deal with it from there
3233
// because we need to remove anything that doesn't pass by parent Id in the cases that umbraco data is moved to an illegal parent.
33-
if (!path.Contains(string.Concat(",", ParentId.Value, ",")))
34+
if (!path.Contains(string.Concat(",", ParentId.Value.ToString(CultureInfo.InvariantCulture), ",")))
3435
return false;
3536
}
3637

@@ -39,7 +40,7 @@ public bool ValidatePath(string path, string category)
3940

4041
public bool ValidateRecycleBin(string path, string category)
4142
{
42-
var recycleBinId = category == IndexTypes.Content ? Constants.System.RecycleBinContent : Constants.System.RecycleBinMedia;
43+
var recycleBinId = category == IndexTypes.Content ? Constants.System.RecycleBinContentString : Constants.System.RecycleBinMediaString;
4344

4445
//check for recycle bin
4546
if (PublishedValuesOnly)

src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using Examine;
56
using Umbraco.Cms.Core.Mapping;
@@ -162,17 +163,16 @@ private IEnumerable<SearchResultEntity> ContentFromSearchResults(IEnumerable<ISe
162163
}
163164
);
164165

165-
var intId = entity.Id.TryConvertTo<int>();
166-
if (intId.Success)
166+
if (int.TryParse(entity.Id.ToString(),NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
167167
{
168168
//if it varies by culture, return the default language URL
169169
if (result.Values.TryGetValue(UmbracoExamineFieldNames.VariesByCultureFieldName, out var varies) && varies == "y")
170170
{
171-
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId.Result, culture: culture ?? defaultLang);
171+
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId, culture: culture ?? defaultLang);
172172
}
173173
else
174174
{
175-
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId.Result);
175+
entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId);
176176
}
177177
}
178178

src/Umbraco.Infrastructure/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using Microsoft.Extensions.Logging;
56
using Umbraco.Cms.Core.Events;
@@ -946,11 +947,7 @@ public IEnumerable<EntityContainer> GetContainers(int[] containerIds)
946947
public IEnumerable<EntityContainer> GetContainers(TItem item)
947948
{
948949
var ancestorIds = item.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
949-
.Select(x =>
950-
{
951-
var asInt = x.TryConvertTo<int>();
952-
return asInt ? asInt.Result : int.MinValue;
953-
})
950+
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt) ? asInt : int.MinValue)
954951
.Where(x => x != int.MinValue && x != item.Id)
955952
.ToArray();
956953

0 commit comments

Comments
 (0)