Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] Fix eval return; set dir consistently throughnout #8316

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions Sources/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class Config
* Path to the cache directory for the file-based cache system.
*/
END,
'default' => 'dirname(__FILE__) . \'/cache\'',
'default' => '__DIR__ . \'/cache\'',
sbulen marked this conversation as resolved.
Show resolved Hide resolved
'raw_default' => true,
'type' => 'string',
],
Expand Down Expand Up @@ -745,7 +745,7 @@ class Config
* The absolute path to the forum's folder. (not just '.'!)
*/
END,
'default' => 'dirname(__FILE__)',
'default' => '__DIR__',
sbulen marked this conversation as resolved.
Show resolved Hide resolved
'raw_default' => true,
'type' => 'string',
],
Expand All @@ -757,7 +757,7 @@ class Config
* Path to the Sources directory.
*/
END,
'default' => 'dirname(__FILE__) . \'/Sources\'',
'default' => '__DIR__ . \'/Sources\'',
sbulen marked this conversation as resolved.
Show resolved Hide resolved
'raw_default' => true,
'type' => 'string',
],
Expand All @@ -769,7 +769,7 @@ class Config
* Path to the Packages directory.
*/
END,
'default' => 'dirname(__FILE__) . \'/Packages\'',
'default' => '__DIR__ . \'/Packages\'',
sbulen marked this conversation as resolved.
Show resolved Hide resolved
'raw_default' => true,
'type' => 'string',
],
Expand Down Expand Up @@ -920,7 +920,7 @@ public static function set(array $settings): void
'__DIR__' => var_export(dirname(SMF_SETTINGS_FILE), true),
]);

self::${$var} = eval($default . ';');
self::${$var} = eval('return ' . $default . ';');
sbulen marked this conversation as resolved.
Show resolved Hide resolved
} else {
self::${$var} = $def['default'];
}
Expand Down Expand Up @@ -1697,14 +1697,6 @@ public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes

if (!empty($setting_def['raw_default']) && $setting_def['default'] !== '') {
$var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote($setting_def['default'], '~'));

sbulen marked this conversation as resolved.
Show resolved Hide resolved
if (str_contains($setting_def['default'], 'dirname(__FILE__)')) {
$var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('dirname(__FILE__)', '__DIR__', $setting_def['default']), '~'));
}

if (str_contains($setting_def['default'], '__DIR__')) {
$var_pattern[] = preg_replace('/\s+/', '\s+', preg_quote(str_replace('__DIR__', 'dirname(__FILE__)', $setting_def['default']), '~'));
}
}

$var_pattern = array_unique($var_pattern);
Expand Down