Skip to content

Commit 17cd7a2

Browse files
committed
Regression of the AllowParser, performance not as expected
1 parent b73e7ba commit 17cd7a2

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/Parser/Directives/AllowParser.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ public function add($line)
107107
private function addPath($path)
108108
{
109109
$path = rtrim($path, '*');
110-
if (in_array(mb_substr($path, 0, 1), [
111-
'/',
112-
'*',
113-
])) {
110+
if (!in_array('/', $this->path) &&
111+
in_array(mb_substr($path, 0, 1), [
112+
'/',
113+
'*',
114+
])
115+
) {
114116
$this->path[] = $path;
115117
$this->optimized = false;
116118
}
@@ -149,9 +151,7 @@ private function removeOverlapping()
149151
foreach ($this->path as $key1 => &$path1) {
150152
foreach ($this->path as $key2 => &$path2) {
151153
if ($key1 !== $key2 &&
152-
(mb_strpos($path1, $path2) === 0 ||
153-
mb_strpos(str_replace('*', '/', $path1), $path2) === 0
154-
)
154+
mb_strpos($path1, $path2) === 0
155155
) {
156156
unset($this->path[$key1]);
157157
}

tests/DisallowAllTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function generateDataForTest()
6161
[
6262
<<<ROBOTS
6363
User-agent: *
64-
Disallow: *test*
65-
Disallow: /admin/
6664
Disallow: /
65+
Disallow: /admin/
66+
Disallow: *test*
6767
ROBOTS
6868
,
6969
<<<RENDERED

tests/EndAnchorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function generateDataForTest()
5757
[
5858
<<<ROBOTS
5959
User-Agent: *
60-
Noindex: *$
60+
Noindex: $
6161
Disallow: /*
6262
Allow: /$
6363
@@ -73,6 +73,7 @@ public function generateDataForTest()
7373
Allow: /$
7474
7575
User-agent: denyme
76+
Disallow: *deny_all/$
7677
Disallow: /deny_all/$
7778
RENDERED
7879
]

0 commit comments

Comments
 (0)