From a36f9aa453cce25fae7972369c33cd0d4c8f263d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Fri, 3 May 2024 17:13:49 +0200 Subject: [PATCH] chore: Ignore invalid regex checks in Configurator and Config classes + add a log --- src/common/gen/Configurator.py | 20 +++++++++++++++----- src/ui/src/Config.py | 9 ++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/common/gen/Configurator.py b/src/common/gen/Configurator.py index bba78d72c..3c1ff1901 100644 --- a/src/common/gen/Configurator.py +++ b/src/common/gen/Configurator.py @@ -8,7 +8,7 @@ from logging import Logger from os import cpu_count, listdir, sep from os.path import basename, dirname, join from pathlib import Path -from re import compile as re_compile, search as re_search +from re import compile as re_compile, error as RegexError, search as re_search from sys import path as sys_path from tarfile import open as tar_open from threading import Lock, Semaphore, Thread @@ -229,8 +229,13 @@ class Configurator: where, real_var = self.__find_var(variable) if not where: return False, f"variable name {variable} doesn't exist" - elif not re_search(where[real_var]["regex"], value): - return (False, f"value {value} doesn't match regex {where[real_var]['regex']}") + + try: + if not re_search(where[real_var]["regex"], value): + return (False, f"value {value} doesn't match regex {where[real_var]['regex']}") + except RegexError: + self.__logger.warning(f"Invalid regex for {variable} : {where[real_var]['regex']}, ignoring regex check") + return True, "ok" # MULTISITE=yes prefixed, real_var = self.__var_is_prefixed(variable) @@ -239,8 +244,13 @@ class Configurator: return False, f"variable name {variable} doesn't exist" elif prefixed and where[real_var]["context"] != "multisite": return False, f"context of {variable} isn't multisite" - elif not re_search(where[real_var]["regex"], value): - return (False, f"value {value} doesn't match regex {where[real_var]['regex']}") + + try: + if not re_search(where[real_var]["regex"], value): + return (False, f"value {value} doesn't match regex {where[real_var]['regex']}") + except RegexError: + self.__logger.warning(f"Invalid regex for {variable} : {where[real_var]['regex']}, ignoring regex check") + return True, "ok" def __find_var(self, variable: str) -> Tuple[Optional[Dict[str, Any]], str]: diff --git a/src/ui/src/Config.py b/src/ui/src/Config.py index b39b1b9e2..2974e746a 100644 --- a/src/ui/src/Config.py +++ b/src/ui/src/Config.py @@ -6,7 +6,7 @@ from os import sep from flask import flash from json import loads as json_loads from pathlib import Path -from re import search as re_search +from re import error as RegexError, search as re_search from typing import List, Literal, Optional, Tuple @@ -126,8 +126,11 @@ class Config: flash(f"Variable {k} is not valid.", "error") continue - if re_search(plugins_settings[setting]["regex"], v): - check = True + try: + if re_search(plugins_settings[setting]["regex"], v): + check = True + except RegexError: + self.__db.logger.warning(f"Invalid regex for setting {setting} : {plugins_settings[setting]['regex']}, ignoring regex check") if not check: error = 1