|
5 | 5 |
|
6 | 6 | import { Disposable } from '../../../../../base/common/lifecycle.js';
|
7 | 7 | import type { OperatingSystem } from '../../../../../base/common/platform.js';
|
8 |
| -import { regExpLeadsToEndlessLoop } from '../../../../../base/common/strings.js'; |
| 8 | +import { escapeRegExpCharacters, regExpLeadsToEndlessLoop } from '../../../../../base/common/strings.js'; |
9 | 9 | import { isObject } from '../../../../../base/common/types.js';
|
10 | 10 | import { structuralEquals } from '../../../../../base/common/equals.js';
|
11 | 11 | import { IConfigurationService, type IConfigurationValue } from '../../../../../platform/configuration/common/configuration.js';
|
@@ -281,27 +281,22 @@ export class CommandLineAutoApprover extends Disposable {
|
281 | 281 | return neverMatchRegex;
|
282 | 282 | }
|
283 | 283 |
|
284 |
| - // Check if this looks like a path (contains path separators) |
| 284 | + let sanitizedValue: string; |
| 285 | + |
| 286 | + // Match both path separators it if looks like a path |
285 | 287 | if (value.includes('/') || value.includes('\\')) {
|
286 |
| - // Handle path-like strings with flexible separator and optional ./ prefix matching |
287 |
| - |
288 |
| - // Replace path separators with placeholders first, before escaping |
289 |
| - let pathPattern = value.replace(/[/\\]/g, '§PATH_SEP§'); |
290 |
| - |
291 |
| - // Now escape all regex special characters |
292 |
| - pathPattern = pathPattern.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'); |
293 |
| - |
294 |
| - // Replace placeholders with character class that matches both / and \ |
295 |
| - pathPattern = pathPattern.replace(/§PATH_SEP§/g, '[/\\\\]'); |
296 |
| - |
297 |
| - // Create pattern that optionally matches ./ or .\ at the start |
298 |
| - const finalPattern = `^(?:\\.[/\\\\])?${pathPattern}\\b`; |
299 |
| - |
300 |
| - return new RegExp(finalPattern); |
| 288 | + // Replace path separators with placeholders first, apply standard sanitization, then |
| 289 | + // apply special path handling |
| 290 | + let pattern = value.replace(/[/\\]/g, '%%PATH_SEP%%'); |
| 291 | + pattern = escapeRegExpCharacters(pattern); |
| 292 | + pattern = pattern.replace(/%%PATH_SEP%%*/g, '[/\\\\]'); |
| 293 | + sanitizedValue = `^(?:\\.[/\\\\])?${pattern}`; |
301 | 294 | }
|
302 | 295 |
|
303 | 296 | // Escape regex special characters for non-path strings
|
304 |
| - const sanitizedValue = value.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'); |
| 297 | + else { |
| 298 | + sanitizedValue = escapeRegExpCharacters(value); |
| 299 | + } |
305 | 300 |
|
306 | 301 | // Regular strings should match the start of the command line and be a word boundary
|
307 | 302 | return new RegExp(`^${sanitizedValue}\\b`);
|
|
0 commit comments