Browse Source

Scope matcher fixes

main
Dustin Wilson 3 years ago
parent
commit
578448a45c
  1. 2
      lib/Scope/Matchers/PathMatcher.php
  2. 11
      lib/Scope/Matchers/ScopeMatcher.php

2
lib/Scope/Matchers/PathMatcher.php

@ -20,7 +20,7 @@ class PathMatcher extends Matcher {
$matcher = $this->matchers[$count]; $matcher = $this->matchers[$count];
foreach ($scopes as $scope) { foreach ($scopes as $scope) {
if ($matcher->matches($scope)) { if ($matcher->matches($scope)) {
$matcher = $this->matchers[++$count]; $matcher = $this->matchers[++$count] ?? null;
} }
if ($matcher === null) { if ($matcher === null) {
return true; return true;

11
lib/Scope/Matchers/ScopeMatcher.php

@ -15,8 +15,11 @@ class ScopeMatcher extends Matcher {
public function matches(string $scope): bool { public function matches(string $scope): bool {
$lastDotIndex = 0; $lastDotIndex = 0;
$nextDotIndex = 0;
$scopeLen = strlen($scope); $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) { if ($lastDotIndex > $scopeLen) {
break; break;
} }
@ -26,15 +29,15 @@ class ScopeMatcher extends Matcher {
$nextDotIndex = $scopeLen; $nextDotIndex = $scopeLen;
} }
$scopeSegment = substr($scope, $lastDotIndex, $nextDotIndex); $scopeSegment = substr($scope, $lastDotIndex, $nextDotIndex - $lastDotIndex);
if (!$segment->matches($scopeSegment)) { if (!$matcherSegment->matches($scopeSegment)) {
return false; return false;
} }
$lastDotIndex = $nextDotIndex + 1; $lastDotIndex = $nextDotIndex + 1;
} }
return ($index === count($this->segments)); return ($i === count($this->segments));
} }
public function getPrefix(string $scope): string|null|false { public function getPrefix(string $scope): string|null|false {

Loading…
Cancel
Save