[Finder] Adjust regex to correctly match comments in gitignore contents
This commit is contained in:
parent
36466a3ab5
commit
e56fc7cb58
@ -27,7 +27,7 @@ class Gitignore
|
|||||||
*/
|
*/
|
||||||
public static function toRegex(string $gitignoreFileContent): string
|
public static function toRegex(string $gitignoreFileContent): string
|
||||||
{
|
{
|
||||||
$gitignoreFileContent = preg_replace('/^[^\\\\]*#.*/', '', $gitignoreFileContent);
|
$gitignoreFileContent = preg_replace('/^[^\\\r\n]*#.*/m', '', $gitignoreFileContent);
|
||||||
$gitignoreLines = preg_split('/\r\n|\r|\n/', $gitignoreFileContent);
|
$gitignoreLines = preg_split('/\r\n|\r|\n/', $gitignoreFileContent);
|
||||||
$gitignoreLines = array_map('trim', $gitignoreLines);
|
$gitignoreLines = array_map('trim', $gitignoreLines);
|
||||||
$gitignoreLines = array_filter($gitignoreLines);
|
$gitignoreLines = array_filter($gitignoreLines);
|
||||||
|
@ -111,7 +111,31 @@ class GitignoreTest extends TestCase
|
|||||||
#IamComment
|
#IamComment
|
||||||
/app/cache/',
|
/app/cache/',
|
||||||
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
|
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
|
||||||
['a/app/cache/file.txt'],
|
['a/app/cache/file.txt', '#IamComment', 'IamComment'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'
|
||||||
|
/app/cache/
|
||||||
|
#LastLineIsComment',
|
||||||
|
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
|
||||||
|
['a/app/cache/file.txt', '#LastLineIsComment', 'LastLineIsComment'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'
|
||||||
|
/app/cache/
|
||||||
|
\#file.txt
|
||||||
|
#LastLineIsComment',
|
||||||
|
['app/cache/file.txt', 'app/cache/subdir/ile.txt', '#file.txt'],
|
||||||
|
['a/app/cache/file.txt', '#LastLineIsComment', 'LastLineIsComment'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'
|
||||||
|
/app/cache/
|
||||||
|
\#file.txt
|
||||||
|
#IamComment
|
||||||
|
another_file.txt',
|
||||||
|
['app/cache/file.txt', 'app/cache/subdir/ile.txt', '#file.txt', 'another_file.txt'],
|
||||||
|
['a/app/cache/file.txt', 'IamComment', '#IamComment'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user