-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Regular expression patterns are mistaken for directories #797
Copy link
Copy link
Description
Describe the bug
When the agent comes up with some PowerShell to find files, it'll often come up with something like this:
# Find all logger writes in catch blocks that are NOT Error level
$projectPath = "C:\Users\prplecake\Projects\[redacted]"
$files = Get-ChildItem -Path $projectPath -Recurse -Include "*.cs" -File | Where-Object {
$_.FullName -notlike "*\obj\*" -and
$_.FullName -notlike "*\bin\*" -and
$_.FullName -like "$projectPath\*"
}
$results = @()
foreach ($file in $files) {
$lines = Get-Content $file.FullName
$inCatch = $false
$catchStart = 0
$braceCount = 0
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
if ($line -match '\bcatch\b') {
$inCatch = $true
$catchStart = $i + 1
$braceCount = 0
}
if ($inCatch) {
# Count braces to track scope
$openBraces = ([regex]::Matches($line, '\{')).Count
$closeBraces = ([regex]::Matches($line, '\}')).Count
$braceCount += $openBraces - $closeBraces
# Check for logger statements that are NOT Error
if ($line -match '(logger|_logger|Log)\.(Information|Warning|Debug|Verbose|Fatal)\(') {
$results += [PSCustomObject]@{
File = $file.FullName.Replace("$projectPath\", "")
Line = $i + 1
Content = $line.Trim()
}
}
if ($braceCount -le 0 -and $i -gt $catchStart) {
$inCatch = $false
}
}
}
}
if ($results.Count -gt 0) {
Write-Host "Found $($results.Count) logger statements in catch blocks that are NOT Error level:"
Write-Host ""
$results | Format-Table -Wrap -AutoSize
} else {
Write-Host "No non-Error logger statements found in catch blocks."
}and then later, Copilot prompts me for additional directory access:
○ Find non-Error logger statements in catch blocks
$
# Find all logger writes in catch blocks that are NOT Error level
$projectPath = "C:\Users\prplecake\Projects\[redacted]"
$files = Get-ChildItem -Path $projectPath -Recurse -Include "*.cs" -File | Where-Object {
$_.FullName -notlike "*\obj\*" -and ...
└ 51 lines...
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Allow directory access │
│ │
│ Copilot is attempting to read the following paths outside your allowed directory list. │
│ │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ \bcatch\b, \{, \} │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ Do you want to add these directories to the allowed list? │
│ │
│ ❯ 1. Yes │
│ 2. No (Esc) │
│ │
│ Confirm with number keys or ↑↓ keys and Enter, Cancel with Esc │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Affected version
0.0.366 Commit: 0c18d21
Steps to reproduce the behavior
- Make some request that causes Copilot to want to write a PowerShell script with regular expressions in it.
- Let Copilot run the script.
- Get prompted for additional directory access for those regular expression patterns.
Expected behavior
- Don't consider everything between two
\as a path. or - Add an option to "No these aren't directories, continue anyway."
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for Bug.