From 578448a45cd6d363a30350ff3b0ff43044bf4e57 Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Sun, 13 Jun 2021 23:44:56 -0500 Subject: [PATCH] Scope matcher fixes --- lib/Scope/Matchers/PathMatcher.php | 2 +- lib/Scope/Matchers/ScopeMatcher.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Scope/Matchers/PathMatcher.php b/lib/Scope/Matchers/PathMatcher.php index ac57c8d..0c00b63 100644 --- a/lib/Scope/Matchers/PathMatcher.php +++ b/lib/Scope/Matchers/PathMatcher.php @@ -20,7 +20,7 @@ class PathMatcher extends Matcher { $matcher = $this->matchers[$count]; foreach ($scopes as $scope) { if ($matcher->matches($scope)) { - $matcher = $this->matchers[++$count]; + $matcher = $this->matchers[++$count] ?? null; } if ($matcher === null) { return true; diff --git a/lib/Scope/Matchers/ScopeMatcher.php b/lib/Scope/Matchers/ScopeMatcher.php index c5c7d80..bfdb7ad 100644 --- a/lib/Scope/Matchers/ScopeMatcher.php +++ b/lib/Scope/Matchers/ScopeMatcher.php @@ -15,8 +15,11 @@ class ScopeMatcher extends Matcher { public function matches(string $scope): bool { $lastDotIndex = 0; + $nextDotIndex = 0; $scopeLen = strlen($scope); - foreach ($this->segments as $index => $segment) { + + for ($i = 0, $len = count($this->segments); $i < $len; $i++) { + $matcherSegment = $this->segments[$i]; if ($lastDotIndex > $scopeLen) { break; } @@ -26,15 +29,15 @@ class ScopeMatcher extends Matcher { $nextDotIndex = $scopeLen; } - $scopeSegment = substr($scope, $lastDotIndex, $nextDotIndex); - if (!$segment->matches($scopeSegment)) { + $scopeSegment = substr($scope, $lastDotIndex, $nextDotIndex - $lastDotIndex); + if (!$matcherSegment->matches($scopeSegment)) { return false; } $lastDotIndex = $nextDotIndex + 1; } - return ($index === count($this->segments)); + return ($i === count($this->segments)); } public function getPrefix(string $scope): string|null|false {