Skip to content

Commit 836ad06

Browse files
committed
Rework the regexp (1024 false positive to... 0 on ux.symfony.com)
1 parent 8dd4ebd commit 836ad06

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Icons/src/Twig/IconFinder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ public function icons(): array
3535
{
3636
$found = [];
3737

38+
// https://regex101.com/r/WGa4iF/1
39+
$token = '[a-z0-9]+(?:-[a-z0-9]+)*';
40+
$pattern = "#(?:'$token:$token')|(?:\"$token:$token\")#i";
41+
3842
foreach ($this->files($this->twig->getLoader()) as $file) {
3943
$contents = file_get_contents($file);
40-
41-
if (preg_match_all('#["\']([\w:-]+)["\']#', $contents, $matches)) {
42-
$found[] = $matches[1];
44+
if (preg_match_all($pattern, $contents, $matches)) {
45+
$found[] = array_map(fn ($res) => trim($res, '"\''), $matches[0]);
4346
}
4447
}
4548

0 commit comments

Comments
 (0)