Skip to content

Commit 4e165ea

Browse files
iOvergaardclaude
andcommitted
Fix path comparison bug in UserStartNodeEntitiesService (similar to #21162)
This fixes the same path comparison bug we fixed in PR #21162 but in C# string comparisons instead of SQL queries. ## Root Cause Path comparisons without trailing commas caused false matches: - Path "-1,1001" incorrectly matched prefix "-1,100" - This marked nodes as ancestors/descendants when they weren't related ## Examples of False Matches - child.Path = "-1,1001", startNodePath = "-1,100" - OLD: "-1,1001".StartsWith("-1,100") = TRUE (bug!) - NEW: "-1,1001,".StartsWith("-1,100,") = FALSE (correct!) - child.Path = "-1,100", startNodePath = "-1,1001" - OLD: "-1,1001".StartsWith("-1,100") = TRUE (bug!) - NEW: "-1,1001,".StartsWith("-1,100,") = FALSE (correct!) ## Fix Applied (Two Locations) 1. Line 146 (ancestor check): Added comma suffix to child.Path 2. Line 226 (IsDescendantOrSelf): Added comma suffix to both paths This matches the pattern already used correctly in lines 92 and 191 of the same file, and mirrors the SQL fix from PR #21162. ## Test Impact This should fix the failing E2E test where child media folders were incorrectly marked as noAccess when they were actually the user's start node. Related: #21162 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent a8f7837 commit 4e165ea

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Umbraco.Cms.Api.Management/Services/Entities/UserStartNodeEntitiesService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public IEnumerable<UserAccessEntity> ChildUserAccessEntities(IEnumerable<IEntity
142142
}
143143

144144
// is ancestor of a start node?
145-
if (userStartNodePaths.Any(path => path.StartsWith(child.Path)))
145+
// Note: Add trailing comma to prevent false matches (e.g., path "-1,100" should not match "-1,1001")
146+
if (userStartNodePaths.Any(path => path.StartsWith($"{child.Path},")))
146147
{
147148
return new UserAccessEntity(child, false);
148149
}
@@ -220,5 +221,7 @@ public IEnumerable<UserAccessEntity> UserAccessEntities(IEnumerable<IEntitySlim>
220221
=> entities.Select(entity => new UserAccessEntity(entity, IsDescendantOrSelf(entity, userStartNodePaths))).ToArray();
221222

222223
private static bool IsDescendantOrSelf(IEntitySlim child, string[] userStartNodePaths)
223-
=> userStartNodePaths.Any(path => child.Path.StartsWith(path));
224+
// Note: Add trailing commas to both paths to prevent false matches (e.g., path "-1,100" should not match "-1,1001")
225+
// This matches the pattern used in lines 92 and 191 of this file
226+
=> userStartNodePaths.Any(path => $"{child.Path},".StartsWith($"{path},"));
224227
}

0 commit comments

Comments
 (0)