From 0e51a4466b9bec54a3fb39c2c1809fcc71245e27 Mon Sep 17 00:00:00 2001 From: umgfoin Date: Thu, 21 May 2026 16:47:08 +0200 Subject: [PATCH] Fix unwanted escaping of regex string-constants: "\_" -> r"\_" Fixes commit a01501e. Signed-off-by: umgfoin --- cli/common.py | 2 +- endpoints/__init__.py | 2 +- tools/DataModel.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/common.py b/cli/common.py index 4c6e5cb..ddab2b2 100644 --- a/cli/common.py +++ b/cli/common.py @@ -21,7 +21,7 @@ def userFilter(userSpec, autocompleting, *filters): from sqlalchemy import and_ return and_(True if userSpec is None else Users.ID == userSpec if userSpec.isdigit() else - Users.username.ilike(userSpec.replace("_", "\_")+("%" if autocompleting else "")), *filters) + Users.username.ilike(userSpec.replace("_", r"\_")+("%" if autocompleting else "")), *filters) def userCandidates(userSpec, *filters): diff --git a/endpoints/__init__.py b/endpoints/__init__.py index c966e06..a56dfe3 100644 --- a/endpoints/__init__.py +++ b/endpoints/__init__.py @@ -385,7 +385,7 @@ def userQuery(domainID=None): expr = request.args["match"] fields = set(request.args["matchFields"].split(",")) if "matchFields" in request.args else None isUnicode = any(ord(c) > 127 for c in expr) - matchexpr = tuple("%"+substr.replace("_", "\_")+"%" for substr in expr.split()) + matchexpr = tuple("%"+substr.replace("_", r"\_")+"%" for substr in expr.split()) matchables = Users._meta.matchables if fields is None else (m for m in Users._meta.matchables if m.alias in fields) targets = [] for prop in matchables: diff --git a/tools/DataModel.py b/tools/DataModel.py index 3c60f79..0cbb0fc 100644 --- a/tools/DataModel.py +++ b/tools/DataModel.py @@ -577,7 +577,7 @@ def automatch(cls, query, expr, fields=None): """Add fuzzy matching to query.""" cls._init() isUnicode = any(ord(c) > 127 for c in expr) - matchexpr = tuple("%"+substr.replace("_", "\_")+"%" for substr in expr.split()) + matchexpr = tuple("%"+substr.replace("_", r"\_")+"%" for substr in expr.split()) matchables = cls._meta.matchables if fields is None else (m for m in cls._meta.matchables if m.alias in fields) targets = [] for prop in matchables: