Skip to content

Commit 996125f

Browse files
committed
Page autocomplete: catch invalid regex
1 parent 9c07550 commit 996125f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

_test/types/PageTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function test_ajax_default()
205205
'autocomplete' => [
206206
'mininput' => 2,
207207
'maxresult' => 5,
208-
'namespace' => '',
208+
'filter' => '',
209209
'postfix' => '',
210210
],
211211
]
@@ -238,6 +238,10 @@ public function test_ajax_default()
238238
], $page->handleAjax());
239239
}
240240

241+
/**
242+
* Test deprecated option namespace
243+
* @return void
244+
*/
241245
public function test_ajax_namespace()
242246
{
243247
global $INPUT;
@@ -257,7 +261,7 @@ public function test_ajax_namespace()
257261
$this->assertEquals([['label' => 'syntax (wiki)', 'value' => 'wiki:syntax']], $page->handleAjax());
258262
}
259263

260-
public function test_ajax_namespace_multiple()
264+
public function test_ajax_filter_multiple()
261265
{
262266
global $INPUT;
263267

@@ -266,7 +270,7 @@ public function test_ajax_namespace_multiple()
266270
'autocomplete' => [
267271
'mininput' => 2,
268272
'maxresult' => 5,
269-
'namespace' => '(wiki|foo)',
273+
'filter' => '(wiki|foo)',
270274
'postfix' => '',
271275
],
272276
]
@@ -279,6 +283,10 @@ public function test_ajax_namespace_multiple()
279283
], $page->handleAjax());
280284
}
281285

286+
/**
287+
* Test deprecated option postfix
288+
* @return void
289+
*/
282290
public function test_ajax_postfix()
283291
{
284292
global $INPUT;

types/Page.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use dokuwiki\File\PageResolver;
66
use dokuwiki\plugin\struct\meta\QueryBuilder;
77
use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
8+
use dokuwiki\plugin\struct\meta\StructException;
89
use dokuwiki\Utf8\PhpString;
910

1011
/**
@@ -256,7 +257,12 @@ public function filterMatch($id, $filter)
256257
$filter = '^' . $filter;
257258
}
258259

259-
return (bool)preg_match('/' . $filter . '/', ':' . $id, $matches);
260+
try {
261+
$check = preg_match('/' . $filter . '/', ':' . $id, $matches);
262+
} catch (\Exception $e) {
263+
throw new StructException("Error processing regular expression '$filter'");
264+
}
265+
return (bool)$check;
260266
}
261267

262268
/**

0 commit comments

Comments
 (0)