[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Config.php : normalizes filesystem preferences when they are saved...
"Sammy Ndabo \(@ndabosam084\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a9152879be09_38ac9e28631f1@gitlab-sidekiq-low-urgency-cpu-bound-v2-85746979f6-w6c5z.mail> |
Sammy Ndabo pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
0f3478dd by Sammy Ndabo at 2026-08-28T09:03:29+00:00
[FIX] Config.php : normalizes filesystem preferences when they are saved through system configuration ini files
---
* [ENH] Config.php: centralized directory paths preferences normalization
* tiki: normalize files prefs load when overwritten from host ini files
See merge request tikiwiki/tiki!10806
- - - - -
3 changed files:
- db/tiki-db.php
- lib/core/Tiki/Config/Config.php
- lib/prefslib.php
Changes:
=====================================
db/tiki-db.php
=====================================
@@ -93,6 +93,7 @@ if (! empty($_SERVER['TIKI_INI_FILE']) && is_readable($_SERVER['TIKI_INI_FILE'])
try {
$envIni = new Ini();
$envData = $envIni->fromFile($_SERVER['TIKI_INI_FILE'], $_SERVER['TIKI_INI_IDENTIFIER'] ?? null);
+ $envData = Config::normalizeDirectoryPrefs($envData);
$systemConfiguration->mergeAddOnly($envData);
} catch (\Throwable $e) {
$fail('Failed to load ' . $_SERVER['TIKI_INI_FILE'] . ': ' . $e->getMessage());
@@ -117,6 +118,7 @@ foreach ($system_configuration_files as $configFile) {
try {
$ini = new Ini();
$baseData = $ini->fromFile($configFile, $system_configuration_identifier ?? null);
+ $baseData = Config::normalizeDirectoryPrefs($baseData);
$systemConfiguration->merge($baseData);
} catch (\Throwable $e) {
$fail('Failed to load ' . $configFile . ': ' . $e->getMessage());
=====================================
lib/core/Tiki/Config/Config.php
=====================================
@@ -9,6 +9,12 @@ namespace Tiki\Config;
class Config implements \ArrayAccess, \IteratorAggregate, \Countable
{
+ private const DIRECTORY_PREFERENCES = [
+ 'fgal_use_dir',
+ 't_use_dir',
+ 'w_use_dir',
+ ];
+
private array $data;
private bool $allowModifications;
private bool $readOnly = false;
@@ -24,6 +30,51 @@ class Config implements \ArrayAccess, \IteratorAggregate, \Countable
return $this->data;
}
+ public static function normalizeDirectoryPrefs(array $data): array
+ {
+ foreach ($data as $key => $value) {
+ if ($key === 'preference' && is_array($value)) {
+ $data[$key] = self::normalizeDirectoryPrefsArray($value);
+ continue;
+ }
+
+ if (is_array($value)) {
+ $data[$key] = self::normalizeDirectoryPrefs($value);
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Normalize directory-based preference values to include a trailing slash.
+ *
+ * Applies only to preferences listed in DIRECTORY_PREFERENCES. Non-listed
+ * preferences, empty strings, non-string values, and values already ending
+ * with '/' or '\\' are returned unchanged.
+ */
+ public static function normalizeDirectoryPrefValue(string $name, mixed $value): mixed
+ {
+ if (! in_array($name, self::DIRECTORY_PREFERENCES, true) || ! is_string($value) || $value === '') {
+ return $value;
+ }
+
+ if (str_ends_with($value, '/') || str_ends_with($value, '\\')) {
+ return $value;
+ }
+
+ return $value . '/';
+ }
+
+ private static function normalizeDirectoryPrefsArray(array $preferences): array
+ {
+ foreach ($preferences as $name => $value) {
+ $preferences[$name] = self::normalizeDirectoryPrefValue((string) $name, $value);
+ }
+
+ return $preferences;
+ }
+
public function setReadOnly(): void
{
$this->readOnly = true;
=====================================
lib/prefslib.php
=====================================
@@ -5,6 +5,7 @@
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
use Tiki\Package\ComposerManager;
+use Tiki\Config\Config;
class PreferencesLib
{
@@ -723,10 +724,10 @@ class PreferencesLib
}
$function = '_get' . ucfirst($info['type']) . 'Value';
$value = $this->$function($info, $data);
- return $value;
+ return Config::normalizeDirectoryPrefValue($pref, $value);
} else {
if (isset($data[$pref])) {
- return $data[$pref];
+ return Config::normalizeDirectoryPrefValue($pref, $data[$pref]);
}
return null;
}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0f3478dda3f9a62ea84a6ead161be5e6e7aef73f
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0f3478dda3f9a62ea84a6ead161be5e6e7aef73f
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs