Refactor: Extract convertToMinimatchPath helper to eliminate code duplication

Co-authored-by: salmanmkc <32169182+salmanmkc@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-11 09:49:13 +00:00
parent a60e6db920
commit 9de8f6f5c3
+14 -6
View File
@@ -158,9 +158,7 @@ export class Pattern {
// Convert to forward slashes on Windows before matching with minimatch
// since the pattern was converted to forward slashes in the constructor
if (IS_WINDOWS) {
itemPath = itemPath.replace(/\\/g, '/')
}
itemPath = Pattern.convertToMinimatchPath(itemPath)
// Match
if (this.minimatch.match(itemPath)) {
@@ -183,9 +181,7 @@ export class Pattern {
}
// Convert to forward slashes on Windows to match the pattern format used by minimatch
if (IS_WINDOWS) {
itemPath = itemPath.replace(/\\/g, '/')
}
itemPath = Pattern.convertToMinimatchPath(itemPath)
return this.minimatch.matchOne(
itemPath.split(/\/+/),
@@ -204,6 +200,18 @@ export class Pattern {
.replace(/\*/g, '[*]') // escape '*'
}
/**
* Converts path to forward slashes on Windows for compatibility with minimatch.
* On Windows, minimatch patterns use forward slashes, so paths must be converted
* to match the same format.
*/
private static convertToMinimatchPath(itemPath: string): string {
if (IS_WINDOWS) {
return itemPath.replace(/\\/g, '/')
}
return itemPath
}
/**
* Normalizes slashes and ensures absolute root
*/