mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
[RegistryPreview]Fix wrong key path transversal when a key was a substring of a parent (#29311)
Replaced String.Replace with String.Substring to avoid the removal of multiple instances of a string, rather than just the last one.
This commit is contained in:
@@ -774,7 +774,19 @@ namespace RegistryPreview
|
|||||||
|
|
||||||
// before moving onto the next node, tag the previous node and update the path
|
// before moving onto the next node, tag the previous node and update the path
|
||||||
previousNode = newNode;
|
previousNode = newNode;
|
||||||
fullPath = fullPath.Replace(string.Format(CultureInfo.InvariantCulture, @"\{0}", individualKeys[i]), string.Empty);
|
|
||||||
|
// this used to use Replace but that would replace all instances of the same key name, which causes bugs.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int removeAt = fullPath.LastIndexOf(string.Format(CultureInfo.InvariantCulture, @"\{0}", individualKeys[i]), StringComparison.InvariantCulture);
|
||||||
|
if (removeAt > -1)
|
||||||
|
{
|
||||||
|
fullPath = fullPath.Substring(0, removeAt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// One last check: if we get here, the parent of this node is not yet in the tree, so we need to add it as a RootNode
|
// One last check: if we get here, the parent of this node is not yet in the tree, so we need to add it as a RootNode
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user