From 2b768985461ea7c9b3e3efa4a0fe0baba2bfa7c7 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Fri, 19 Jul 2024 08:05:40 +0200 Subject: [PATCH] preserve configured SRI hashes --- lib/Configuration.php | 4 ++++ tst/ConfigurationTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/Configuration.php b/lib/Configuration.php index 2659217f..3e014dc8 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -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; diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index 27a31f73..317c9dc9 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -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'); }