diff options
Diffstat (limited to 'modules-available/locationinfo/inc/locationinfo.inc.php')
-rw-r--r-- | modules-available/locationinfo/inc/locationinfo.inc.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php index 1165164d..a46208c6 100644 --- a/modules-available/locationinfo/inc/locationinfo.inc.php +++ b/modules-available/locationinfo/inc/locationinfo.inc.php @@ -237,4 +237,41 @@ class LocationInfo return ''; } + + /** + * Transform legacy url filter config if found, remove no-op filter setups. + * @param array $config The configuration array to be cleaned up. By reference. + */ + public static function cleanupUrlFilter(array &$config): void + { + // First, simple trimming of white-space around the list, and making sure the keys exist + $config['blacklist'] = trim($config['blacklist'] ?? ''); + $config['whitelist'] = trim($config['whitelist'] ?? ''); + if (empty($config['blacklist']) && empty($config['whitelist'])) { + // Mangle non-upgraded configurations: They only have one list and a bool specifying if it's a black- or whitelist + if (!empty($config['urllist'])) { + if ($config['iswhitelist'] ?? false) { + $config['whitelist'] = str_replace(' ', "\n", $config['urllist']); + } else { + $config['blacklist'] = str_replace(' ', "\n", $config['urllist']); + } + unset($config['urllist'], $config['iswhitelist']); + } + } elseif ((empty($config['blacklist']) || self::isAnyUrlMatch($config['blacklist'])) + && self::isAnyUrlMatch($config['whitelist'])) { + // Blocking everything/nothing and allowing everything is a no-op for all three browsers, so clear both lists + $config['blacklist'] = ''; + $config['whitelist'] = ''; + } + } + + /** + * Check if the given pattern would be interpreted as matching any URL. + * @param string $url The URL to check + */ + private static function isAnyUrlMatch(string $url): bool + { + return $url === '*' || $url === '*://*' || $url === '*://*/' || $url === '*://*/*'; + } + } |