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];
foreach ($scopes as $scope) {
if ($matcher->matches($scope)) {
$matcher = $this->matchers[++$count];
$matcher = $this->matchers[++$count] ?? null;
}
if ($matcher === null) {
return true;

11
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 {

Loading…
Cancel
Save