Skip to content

Commit

Permalink
chore: Ignore invalid regex checks in Configurator and Config classes…
Browse files Browse the repository at this point in the history
… + add a log
  • Loading branch information
TheophileDiot committed May 3, 2024
1 parent ccaef7e commit a36f9aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/common/gen/Configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
Expand Down Expand Up @@ -229,8 +229,13 @@ def __check_var(self, variable: str) -> Tuple[bool, str]:
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)
Expand All @@ -239,8 +244,13 @@ def __check_var(self, variable: str) -> Tuple[bool, str]:
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]:
Expand Down
9 changes: 6 additions & 3 deletions src/ui/src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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


Expand Down Expand Up @@ -126,8 +126,11 @@ def check_variables(self, variables: dict) -> int:
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
Expand Down

0 comments on commit a36f9aa

Please sign in to comment.