allow empty settings (required for root directory)

This commit is contained in:
korelstar 2022-02-12 21:42:07 +01:00
parent 10b9ef929b
commit ad5fb928fa
3 changed files with 6 additions and 3 deletions

View File

@ -101,7 +101,7 @@ class SettingsService {
$settings[$name] = $value = $this->attrs[$name]['validate']($value);
}
if (!array_key_exists($name, $this->attrs)
|| empty($value)
|| $value === null
|| $value === $this->attrs[$name]['default']
) {
unset($settings[$name]);
@ -123,7 +123,7 @@ class SettingsService {
// use default for empty settings
$toBeSaved = false;
foreach ($this->attrs as $name => $attr) {
if (!property_exists($settings, $name) || empty($settings->{$name})) {
if (!property_exists($settings, $name)) {
$defaultValue = $attr['default'];
if (is_callable($defaultValue)) {
$settings->{$name} = $defaultValue($uid);

View File

@ -9,7 +9,7 @@
v-model="settings.notesPath"
type="text"
name="notesPath"
:placeholder="t('notes', 'path to notes')"
:placeholder="t('notes', 'root directory')"
@change="onChangeSettingsReload"
><input type="submit" class="icon-confirm" value="">
</form>

View File

@ -181,6 +181,9 @@ class APIv1Test extends CommonAPITest {
], (object)[
'notesPath' => 'New-Test-Notes-Folder2',
], 'Update notesPath with path traversal check');
$this->updateSettings($settings, (object)[
'notesPath' => '',
], (object)[], 'Update notesPath with root directory');
$this->updateSettings($settings, (object)[
'fileSuffix' => 'illegal value',
], (object)[