From e80f5133156f81038612ef082fa98fc6d4b8f33f Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 20 Jul 2024 08:47:49 +0200 Subject: [PATCH] Validate alias structure in prototype homogenization. Resolve #3578 --- CHANGELOG.md | 3 +++ evennia/prototypes/prototypes.py | 10 +++++++--- evennia/utils/ansi.py | 3 +-- evennia/utils/hex_colors.py | 10 +++++----- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca8f30c1bf..046a3da2e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ underline reset, italic/reset and strikethrough/reset (0xDEADFED5) - [Feat][pull3582]: Add true-color parsing/fallback for ANSIString (0xDEADFED5) - [Fix][pull3571]: Better visual display of partial multimatch search results (InspectorCaracal) +- [Fix][issue3378]: Prototype 'alias' key was not properly homogenized to a list + (Griatch) - [Fix][pull3550]: Issue where rpsystem contrib search would do a global instead of local search on multimatch (InspectorCaracal) - [Fix][pull3585]: `TagCmd.switch_options` was misnamed (erratic-pattern) @@ -28,6 +30,7 @@ underline reset, italic/reset and strikethrough/reset (0xDEADFED5) [pull3531]: https://github.com/evennia/evennia/pull/3531 [pull3571]: https://github.com/evennia/evennia/pull/3571 [pull3582]: https://github.com/evennia/evennia/pull/3582 +[issue3378]: https://github.com/evennia/evennia/issues/3578 ## Evennia 4.2.0 diff --git a/evennia/prototypes/prototypes.py b/evennia/prototypes/prototypes.py index e6441ba137..569179817f 100644 --- a/evennia/prototypes/prototypes.py +++ b/evennia/prototypes/prototypes.py @@ -12,7 +12,6 @@ from django.conf import settings from django.core.paginator import Paginator from django.db.models import Q from django.utils.translation import gettext as _ - from evennia.locks.lockhandler import check_lockstring, validate_lockstring from evennia.objects.models import ObjectDB from evennia.scripts.scripts import DefaultScript @@ -104,6 +103,7 @@ def homogenize_prototype(prototype, custom_keys=None): prototype[protkey] = "" homogenized = {} + homogenized_aliases = [] homogenized_tags = [] homogenized_attrs = [] homogenized_parents = [] @@ -111,7 +111,10 @@ def homogenize_prototype(prototype, custom_keys=None): for key, val in prototype.items(): if key in reserved: # check all reserved keys - if key == "tags": + if key == "aliases": + # make sure aliases are always in a list even if given as a single string + homogenized_aliases = make_iter(val) + elif key == "tags": # tags must be on form [(tag, category, data), ...] tags = make_iter(prototype.get("tags", [])) for tag in tags: @@ -160,13 +163,14 @@ def homogenize_prototype(prototype, custom_keys=None): else: # normal prototype-parent names are added as-is homogenized_parents.append(parent) - else: # another reserved key homogenized[key] = val else: # unreserved keys -> attrs homogenized_attrs.append((key, val, None, "")) + if homogenized_aliases: + homogenized["aliases"] = homogenized_aliases if homogenized_attrs: homogenized["attrs"] = homogenized_attrs if homogenized_tags: diff --git a/evennia/utils/ansi.py b/evennia/utils/ansi.py index 313f063749..06e2438251 100644 --- a/evennia/utils/ansi.py +++ b/evennia/utils/ansi.py @@ -67,7 +67,6 @@ import re from collections import OrderedDict from django.conf import settings - from evennia.utils import logger, utils from evennia.utils.hex_colors import HexColors from evennia.utils.utils import to_str @@ -124,7 +123,7 @@ ANSI_TAB = "\t" ANSI_SPACE = " " # Escapes -ANSI_ESCAPES = ("{{", "\\\\", "\|\|") +ANSI_ESCAPES = ("{{", r"\\", r"\|\|") _PARSE_CACHE = OrderedDict() _PARSE_CACHE_SIZE = 10000 diff --git a/evennia/utils/hex_colors.py b/evennia/utils/hex_colors.py index 01fa44175d..3ca921bc3b 100644 --- a/evennia/utils/hex_colors.py +++ b/evennia/utils/hex_colors.py @@ -9,9 +9,9 @@ class HexColors: Based on code from @InspectorCaracal """ - _RE_FG = "\|#" - _RE_BG = "\|\[#" - _RE_FG_OR_BG = "\|\[?#" + _RE_FG = r"\|#" + _RE_BG = r"\|\[#" + _RE_FG_OR_BG = r"\|\[?#" _RE_HEX_LONG = "[0-9a-fA-F]{6}" _RE_HEX_SHORT = "[0-9a-fA-F]{3}" _RE_BYTE = "[0-2]?[0-9]?[0-9]" @@ -23,8 +23,8 @@ class HexColors: # Used for greyscale _GREYS = "abcdefghijklmnopqrstuvwxyz" - TRUECOLOR_FG = f"\x1b\[38;2;{_RE_BYTE};{_RE_BYTE};{_RE_BYTE}m" - TRUECOLOR_BG = f"\x1b\[48;2;{_RE_BYTE};{_RE_BYTE};{_RE_BYTE}m" + TRUECOLOR_FG = rf"\x1b\[38;2;{_RE_BYTE};{_RE_BYTE};{_RE_BYTE}m" + TRUECOLOR_BG = rf"\x1b\[48;2;{_RE_BYTE};{_RE_BYTE};{_RE_BYTE}m" # Our matchers for use with ANSIParser and ANSIString hex_sub = re.compile(rf"{_RE_HEX_PATTERN}", re.DOTALL)