IJPL-164957 Refine Windows Defender exclusions path comparison

Enhanced the `Test-Excluded` function to better handle directory paths by checking if the exclusion is a directory and ensuring it has more path segments than the excluded path. This improves the accuracy of determining whether a path should be excluded.


(cherry picked from commit e494da49d0722bbd599704d9e51c9d37e9a37987)

IJ-CR-149682

GitOrigin-RevId: d76f36bd247b9455f1c60d216a10f369d0b0f333
This commit is contained in:
Vera Petrenkova
2024-11-19 11:34:07 +01:00
committed by intellij-monorepo-bot
parent f82fa8f94a
commit 33ae337a93

View File

@@ -37,7 +37,7 @@ try {
# returns `$true` when a path is already covered by the exclusion list
function Test-Excluded ([string] $path, [string[]] $exclusions) {
foreach ($exclusion in $exclusions) {
if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $exclusion, @("IgnoreCase"))) {
if (((Get-Item -Path $exclusion) -is [System.IO.DirectoryInfo]) -and ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $exclusion, @("IgnoreCase"))) -and ($exclusion.TrimEnd('\').split('\').Count -gt $path.TrimEnd('\').Split('\').Count)) {
return $true
}
}