preserve configured SRI hashes

This commit is contained in:
El RIDO 2024-07-19 08:05:40 +02:00
parent 5ef8a094e7
commit 2b76898546
2 changed files with 9 additions and 0 deletions

View file

@ -210,6 +210,10 @@ class Configuration
}
// check for missing keys and set defaults if necessary
else {
// preserve configured SRI hashes
if ($section == 'sri' && array_key_exists($section, $config)) {
$this->_configuration[$section] = $config[$section];
}
foreach ($values as $key => $val) {
if ($key == 'dir') {
$val = PATH . $val;

View file

@ -120,9 +120,14 @@ class ConfigurationTest extends TestCase
unset($options['expire_options']['1week']);
unset($options['expire_options']['1year']);
unset($options['expire_options']['never']);
$valid_sri = $options['sri'][array_key_first($options['sri'])];
$options['sri'][array_key_first($options['sri'])] = ''; // empty string should get replaced with default
$options['sri']['js/example.js'] = 'some invalid SRI hash';
Helper::createIniFile(CONF, $options);
$conf = new Configuration;
// restore expected results
$options['expire']['default'] = '5min';
$options['sri'][array_key_first($options['sri'])] = $valid_sri;
$this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys');
}