Skip to content

Commit b88efcb

Browse files
committed
Fix 41223 issue "**/vendor/**"
1 parent dffdc71 commit b88efcb

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

src/Symfony/Component/Finder/Gitignore.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,16 @@ private static function lineToRegex(string $gitignoreLine): string
6868
$isAbsolute = false;
6969
}
7070

71-
$parts = array_map(function (string $v): string {
72-
$v = preg_quote(str_replace('\\', '', $v), '~');
73-
$v = preg_replace_callback('~\\\\\[([^\[\]]*)\\\\\]~', function (array $matches): string {
74-
return '['.str_replace('\\-', '-', $matches[1]).']';
75-
}, $v);
76-
$v = preg_replace('~\\\\\*\\\\\*~', '[^/]+(?:/[^/]+)*', $v);
77-
$v = preg_replace('~\\\\\*~', '[^/]*', $v);
78-
$v = preg_replace('~\\\\\?~', '[^/]', $v);
79-
80-
return $v;
81-
}, explode('/', $gitignoreLine));
71+
$regex = preg_quote(str_replace('\\', '', $gitignoreLine), '~');
72+
$regex = preg_replace_callback('~\\\\\[([^\[\]]*)\\\\\]~', function (array $matches): string {
73+
return '['.str_replace('\\-', '-', $matches[1]).']';
74+
}, $regex);
75+
$regex = preg_replace('~(?:(?:\\\\\*){2,}/?)+~', '.*', $regex);
76+
$regex = preg_replace('~\\\\\*~', '[^/]*', $regex);
77+
$regex = preg_replace('~\\\\\?~', '[^/]', $regex);
8278

8379
return ($isAbsolute ? '' : '(?:[^/]+/)*')
84-
.implode('/', $parts)
85-
.('' !== end($parts) ? '(?:$|/)' : '');
80+
.$regex
81+
.('/' !== substr($gitignoreLine, -1) ? '(?:$|/)' : '');
8682
}
8783
}

src/Symfony/Component/Finder/Tests/GitignoreTest.php

+31-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public function provider(): array
8888
[],
8989
],
9090
[
91-
['/a', 'm/*'],
92-
['a', 'a/b', 'a/b/c', 'm/'],
93-
['aa', 'm', 'b/m', 'b/m/'],
91+
['/a', 'm/*', 'o/**'],
92+
['a', 'a/b', 'a/b/c', 'm/', 'o/'],
93+
['aa', 'm', 'b/m', 'b/m/', 'o', 'b/o', 'b/o/'],
9494
],
9595
[
9696
['a', '!x'],
@@ -280,6 +280,34 @@ public function provider(): array
280280
['example/test', 'example/example.txt2', 'example/packages/foo.yaml'],
281281
['example/example.txt', 'example/packages', 'example/packages/'],
282282
],
283+
[
284+
[
285+
'*/vendor/*',
286+
],
287+
['a/vendor/', 'a/vendor/b', 'a/vendor/b/c'],
288+
['a', 'vendor', 'vendor/', 'a/vendor', 'a/b/vendor', 'a/b/vendor/c'],
289+
],
290+
[
291+
[
292+
'**/vendor/**',
293+
],
294+
['vendor/', 'vendor/a', 'vendor/a/b', 'a/b/vendor/c/d'],
295+
['a', 'vendor', 'a/vendor', 'a/b/vendor'],
296+
],
297+
[
298+
[
299+
'***/***/vendor/*****/*****',
300+
],
301+
['vendor/', 'vendor/a', 'vendor/a/b', 'a/b/vendor/c/d'],
302+
['a', 'vendor', 'a/vendor', 'a/b/vendor'],
303+
],
304+
[
305+
[
306+
'**vendor**',
307+
],
308+
['vendor', 'vendor/', 'vendor/a', 'vendor/a/b', 'a/vendor', 'a/b/vendor', 'a/b/vendor/c/d'],
309+
['a'],
310+
],
283311
];
284312

285313
return $cases;

0 commit comments

Comments
 (0)