This commit is contained in:
joyqi 2022-03-22 14:24:14 +08:00
parent 0edb48fae0
commit 1b673e06ff
2 changed files with 9 additions and 2 deletions

View File

@ -1021,6 +1021,9 @@ function install_step_2_perform()
case 'SQLite':
$error = (new \Typecho\Validate())
->addRule('dbFile', 'required', _t('确认您的配置'))
->addRule('dbFile', function (string $path) {
return !!preg_match("/^(\/[_a-z0-9-]+)*[a-z0-9]+\.[a-z0-9]{2,}$/i", $path);
}, _t('确认您的配置'))
->run($config);
break;
default:
@ -1041,6 +1044,10 @@ function install_step_2_perform()
$dbConfig['port'] = intval($dbConfig['port']);
}
if (isset($dbConfig['file']) && preg_match("/^[a-z0-9]+\.[a-z0-9]{2,}$/i", $dbConfig['file'])) {
$dbConfig['file'] = __DIR__ . '/usr/' . $dbConfig['file'];
}
// check config file
if ($config['dbNext'] == 'config' && !install_check('config')) {
$code = install_config_file($config['dbAdapter'], $config['dbPrefix'], $dbConfig, true);

View File

@ -221,7 +221,7 @@ class Validate
* @access public
*
* @param string $key 数值键值
* @param string|array $rule 规则名称
* @param string|callable $rule 规则名称
* @param string $message 错误字符串
*
* @return $this
@ -284,7 +284,7 @@ class Validate
$params[1] = $data[$key];
$params = array_slice($params, 1);
if (!call_user_func_array(is_array($method) ? $method : [$this, $method], $params)) {
if (!call_user_func_array(is_callable($method) ? $method : [$this, $method], $params)) {
$result[$key] = $message;
break;
}