Browse Source

preserve configured SRI hashes

El RIDO 2 years ago
parent
commit
2b76898546
2 changed files with 9 additions and 0 deletions
  1. 4 0
      lib/Configuration.php
  2. 5 0
      tst/ConfigurationTest.php

+ 4 - 0
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;

+ 5 - 0
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');
     }