Validate alias structure in prototype homogenization. Resolve #3578

This commit is contained in:
Griatch 2024-07-20 08:47:49 +02:00
parent 1d689ed78c
commit e80f513315
4 changed files with 16 additions and 10 deletions

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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)