fix pattern logic

This commit is contained in:
Hemachandar
2026-04-20 12:02:07 +05:30
committed by harsh mahajan
parent a4f174ea7e
commit e17cdc2bd4
2 changed files with 67 additions and 15 deletions
+28 -4
View File
@@ -21,24 +21,48 @@ class BuildTrigger extends Validator
$include = array_filter($this->patterns, fn ($p) => !str_starts_with($p, '!'));
$exclude = array_filter($this->patterns, fn ($p) => str_starts_with($p, '!'));
if (empty($include)) {
// Only exclusions: pass everything unless excluded.
foreach ($exclude as $pattern) {
if ($this->matchGlob($value, substr($pattern, 1))) {
return false;
}
}
return true;
}
// A pattern is "specific" when it contains no wildcard characters.
$isSpecific = fn($p) => !str_contains($p, '*') && !str_contains($p, '?');
// 1. Specific inclusion always wins — an explicit exact match is never blocked.
foreach ($include as $pattern) {
if ($this->matchGlob($value, $pattern)) {
if ($isSpecific($pattern) && $this->matchGlob($value, $pattern)) {
return true;
}
}
// 2. Specific exclusion overrides a wildcard inclusion — refines broad patterns.
foreach ($exclude as $pattern) {
if ($this->matchGlob($value, substr($pattern, 1))) {
$raw = substr($pattern, 1);
if ($isSpecific($raw) && $this->matchGlob($value, $raw)) {
return false;
}
}
return empty($include);
// 3. Wildcard inclusion wins over any remaining wildcard exclusion.
foreach ($include as $pattern) {
if (!$isSpecific($pattern) && $this->matchGlob($value, $pattern)) {
return true;
}
}
// No inclusion matched.
return false;
}
public function getDescription(): string
{
return 'Value must match at least one inclusion pattern and must not match any exclusion pattern.';
return 'Value must match a specific inclusion, or a wildcard inclusion not overridden by a specific exclusion.';
}
public function isArray(): bool