summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/config/core/Setting/SettingRegex.php
blob: b38f0a56044ecd9e439d7a3f366d98ff8d30891a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace dokuwiki\plugin\config\core\Setting;

/**
 * Class setting_regex
 */
class SettingRegex extends SettingString {

    protected $delimiter = '/';    // regex delimiter to be used in testing input
    protected $pregflags = 'ui';   // regex pattern modifiers to be used in testing input

    /** @inheritdoc */
    public function update($input) {

        // let parent do basic checks, value, not changed, etc.
        $local = $this->local;
        if(!parent::update($input)) return false;
        $this->local = $local;

        // see if the regex compiles and runs (we don't check for effectiveness)
        $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags;
        $lastError = error_get_last();
        @preg_match($regex, 'testdata');
        if(preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) {
            $this->input = $input;
            $this->error = true;
            return false;
        }

        $this->local = $input;
        return true;
    }
}