Quellcode durchsuchen

handle undefined global, fixes #1544

El RIDO vor 1 Jahr
Ursprung
Commit
c08a792f01
3 geänderte Dateien mit 13 neuen und 5 gelöschten Zeilen
  1. 2 0
      CHANGELOG.md
  2. 9 5
      lib/Data/Filesystem.php
  3. 2 0
      tst/Data/FilesystemTest.php

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@
 * CHANGED: Passing large data structures by reference to reduce memory consumption (#858)
 * CHANGED: Removed use of ctype functions and polyfill library for ctype
 * CHANGED: Upgrading libraries to: DOMpurify 3.2.5, ip-lib 1.20.0
+* FIXED: Bump zlib library suffix, ensuring cache refresh for WASM streaming change
+* FIXED: Handle undefined globals in file based persisted values (#1544)
 
 ## 1.7.6 (2025-02-01)
 * ADDED: Ability to copy the paste by clicking the copy icon button or using the keyboard shortcut ctrl+c/cmd+c (#1390 & #12)

+ 9 - 5
lib/Data/Filesystem.php

@@ -276,7 +276,7 @@ class Filesystem extends AbstractData
             case 'purge_limiter':
                 return $this->_storeString(
                     $this->_path . DIRECTORY_SEPARATOR . 'purge_limiter.php',
-                    '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $value . ';'
+                    '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . var_export($value, true) . ';'
                 );
             case 'salt':
                 return $this->_storeString(
@@ -308,7 +308,9 @@ class Filesystem extends AbstractData
                 $file = $this->_path . DIRECTORY_SEPARATOR . 'purge_limiter.php';
                 if (is_readable($file)) {
                     require $file;
-                    return $GLOBALS['purge_limiter'];
+                    if (array_key_exists('purge_limiter', $GLOBALS)) {
+                        return $GLOBALS['purge_limiter'];
+                    }
                 }
                 break;
             case 'salt':
@@ -324,9 +326,11 @@ class Filesystem extends AbstractData
                 $file = $this->_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php';
                 if (is_readable($file)) {
                     require $file;
-                    $this->_last_cache = $GLOBALS['traffic_limiter'];
-                    if (array_key_exists($key, $this->_last_cache)) {
-                        return $this->_last_cache[$key];
+                    if (array_key_exists('traffic_limiter', $GLOBALS)) {
+                        $this->_last_cache = $GLOBALS['traffic_limiter'];
+                        if (array_key_exists($key, $this->_last_cache)) {
+                            return $this->_last_cache[$key];
+                        }
                     }
                 }
                 break;

+ 2 - 0
tst/Data/FilesystemTest.php

@@ -185,7 +185,9 @@ class FilesystemTest extends TestCase
         foreach (array('purge_limiter', 'salt', 'traffic_limiter') as $namespace) {
             file_put_contents($this->_invalidPath . DIRECTORY_SEPARATOR . $namespace . '.php', 'invalid content');
             $model = new Filesystem(array('dir' => $this->_invalidPath));
+            ob_start(); // hide "invalid content", when file gets included
             $this->assertEquals($model->getValue($namespace), '', 'empty default value returned, invalid content ignored');
+            ob_end_clean();
             $this->assertTrue($model->setValue(VALID, $namespace), 'setting valid value');
             $this->assertEquals($model->getValue($namespace), VALID, 'valid value returned');
         }