Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad6dc2e

Browse filesBrowse files
committed
bug symfony#33340 [Finder] Adjust regex to correctly match comments in gitignore contents (Jeroeny)
This PR was squashed before being merged into the 4.3 branch (closes symfony#33340). Discussion ---------- [Finder] Adjust regex to correctly match comments in gitignore contents | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#32985 | License | MIT Description from issue: When using `ignoreVCSIgnored` as argument with the Symfony Finder, it will construct a regex equivalent of the gitignore pattern. However it seems that when a comment line (prefixed with `#`) is present in the `.gitignore`, the regex used to remove comment lines matches every line and thus returns `$gitignoreFileContent` as empty. Commits ------- e56fc7c [Finder] Adjust regex to correctly match comments in gitignore contents
2 parents bafe10a + e56fc7c commit ad6dc2e
Copy full SHA for ad6dc2e

File tree

2 files changed

+26
-2
lines changed
Filter options

2 files changed

+26
-2
lines changed

‎src/Symfony/Component/Finder/Gitignore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Gitignore.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Gitignore
2525
*/
2626
public static function toRegex(string $gitignoreFileContent): string
2727
{
28-
$gitignoreFileContent = preg_replace('/^[^\\\\]*#.*/', '', $gitignoreFileContent);
28+
$gitignoreFileContent = preg_replace('/^[^\\\r\n]*#.*/m', '', $gitignoreFileContent);
2929
$gitignoreLines = preg_split('/\r\n|\r|\n/', $gitignoreFileContent);
3030
$gitignoreLines = array_map('trim', $gitignoreLines);
3131
$gitignoreLines = array_filter($gitignoreLines);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/GitignoreTest.php
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,31 @@ public function provider()
107107
#IamComment
108108
/app/cache/',
109109
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
110-
['a/app/cache/file.txt'],
110+
['a/app/cache/file.txt', '#IamComment', 'IamComment'],
111+
],
112+
[
113+
'
114+
/app/cache/
115+
#LastLineIsComment',
116+
['app/cache/file.txt', 'app/cache/subdir/ile.txt'],
117+
['a/app/cache/file.txt', '#LastLineIsComment', 'LastLineIsComment'],
118+
],
119+
[
120+
'
121+
/app/cache/
122+
\#file.txt
123+
#LastLineIsComment',
124+
['app/cache/file.txt', 'app/cache/subdir/ile.txt', '#file.txt'],
125+
['a/app/cache/file.txt', '#LastLineIsComment', 'LastLineIsComment'],
126+
],
127+
[
128+
'
129+
/app/cache/
130+
\#file.txt
131+
#IamComment
132+
another_file.txt',
133+
['app/cache/file.txt', 'app/cache/subdir/ile.txt', '#file.txt', 'another_file.txt'],
134+
['a/app/cache/file.txt', 'IamComment', '#IamComment'],
111135
],
112136
];
113137
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.