Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force ProcessName to string.Empty for all elements read from disk #123

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Core/Bases/A11yElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ private static A11yElement FromText(string json)

UpdateParent(null, e);

// Make ProcessName deterministically empty when loading a file. If we fail
// to do this, the ProcessName may incorrectly return a currently running process
ClearProcessName(e);

return e;
}

Expand All @@ -717,6 +721,24 @@ private static void UpdateParent(A11yElement p, A11yElement e)
}
}

/// <summary>
/// Explicitly set the ProcessName property to return string.Empty for the given
/// element and for all of its descendants.
/// </summary>
/// <param name="e">The element to update</param>
private static void ClearProcessName(A11yElement e)
{
e._ProcessName = string.Empty;

if (e.Children == null || e.Children.Count == 0)
return;

foreach (A11yElement child in e.Children)
{
ClearProcessName(child);
}
}

#region IDisposable Support
private bool _disposedValue = false; // To detect redundant calls
protected bool DisposedValue { get => _disposedValue; set => _disposedValue = value; }
Expand Down