1
0
Fork 0

#9464: Remove wrapping slashes from the gitignore rules

pull/9465/head
Sergii Bondarenko 2020-11-12 14:24:08 +02:00
parent 1ec5fa81e4
commit abbc0e8a4e
No known key found for this signature in database
GPG Key ID: 242150A50CD96A36
1 changed files with 17 additions and 13 deletions

View File

@ -123,26 +123,30 @@ abstract class BaseExcludeFilter
protected function generatePattern($rule)
{
$negate = false;
$pattern = '{';
$pattern = '';
if (strlen($rule) && $rule[0] === '!') {
if ($rule !== '' && $rule[0] === '!') {
$negate = true;
$rule = substr($rule, 1);
$rule = ltrim($rule, '!');
}
if (strlen($rule) && $rule[0] === '/') {
$pattern .= '^/';
$rule = substr($rule, 1);
} elseif (strlen($rule) - 1 === strpos($rule, '/')) {
$pattern .= '/';
$rule = substr($rule, 0, -1);
} elseif (false === strpos($rule, '/')) {
$pattern .= '/';
if ($rule !== '') {
if ($rule[0] === '/') {
$pattern = '^/';
} else {
$first_slash_position = strpos($rule, '/');
if (false === $first_slash_position || strlen($rule) - 1 === $first_slash_position) {
$pattern = '/';
}
}
$rule = trim($rule, '/');
}
// remove delimiters as well as caret (^) and dollar sign ($) from the regex
$pattern .= substr(Finder\Glob::toRegex($rule), 2, -2) . '(?=$|/)';
$rule = substr(Finder\Glob::toRegex($rule), 2, -2);
return array($pattern . '}', $negate, false);
return array('{'.$pattern.$rule.'(?=$|/)}', $negate, false);
}
}