From 1360f172028a7a49462169e27f7e867be4df6ddb Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 21 Oct 2024 22:01:35 +0200 Subject: [PATCH] Fix case if using string "call:" anywhere in locktype tricked Command to not use a fallback. Resolve #3643. --- CHANGELOG.md | 3 +++ docs/source/Coding/Changelog.md | 5 +++++ evennia/commands/command.py | 6 +++--- evennia/commands/tests.py | 25 ++++++++++++++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb682fd85..7013404a56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ - [Fix][pull3640]: Typo fixes for conjugate verbs (aMiss-aWry) - [Fix][pull3647]: Contents cache didn't reset internal typecache on use of `init` hook (InspectorCaracal) - [Fix][issue3627]: Traceback from contrib `in-game reports` `help manage` command (Griatch) +- [Fix][issue3643]: Fix for Commands metaclass interpreting e.g. `usercmd:false()` locks as + a `cmd:` type lock for the purposes of default access fallbacks (Griatch). - [Docs][pull3576]: Rework doc for [Pycharm howto][doc-pycharm] - Docs updates: feykrh, Griatch @@ -29,6 +31,7 @@ [pull3647]: https://github.com/evennia/evennia/pull/3647 [pull3635]: https://github.com/evennia/evennia/pull/3635 [issue3627]: https://github.com/evennia/evennia/issues/3627 +[issue3643]: https://github.com/evennia/evennia/issues/3643 [doc-pycharm]: https://www.evennia.com/docs/latest/Coding/Setting-up-PyCharm.html ## Evennia 4.4.1 diff --git a/docs/source/Coding/Changelog.md b/docs/source/Coding/Changelog.md index 92302db559..7013404a56 100644 --- a/docs/source/Coding/Changelog.md +++ b/docs/source/Coding/Changelog.md @@ -14,6 +14,9 @@ - [Fix][pull3645]: Correct `character_creator` contrib's error return (InspectorCaracal) - [Fix][pull3640]: Typo fixes for conjugate verbs (aMiss-aWry) - [Fix][pull3647]: Contents cache didn't reset internal typecache on use of `init` hook (InspectorCaracal) +- [Fix][issue3627]: Traceback from contrib `in-game reports` `help manage` command (Griatch) +- [Fix][issue3643]: Fix for Commands metaclass interpreting e.g. `usercmd:false()` locks as + a `cmd:` type lock for the purposes of default access fallbacks (Griatch). - [Docs][pull3576]: Rework doc for [Pycharm howto][doc-pycharm] - Docs updates: feykrh, Griatch @@ -27,6 +30,8 @@ [pull3640]: https://github.com/evennia/evennia/pull/3640 [pull3647]: https://github.com/evennia/evennia/pull/3647 [pull3635]: https://github.com/evennia/evennia/pull/3635 +[issue3627]: https://github.com/evennia/evennia/issues/3627 +[issue3643]: https://github.com/evennia/evennia/issues/3643 [doc-pycharm]: https://www.evennia.com/docs/latest/Coding/Setting-up-PyCharm.html ## Evennia 4.4.1 diff --git a/evennia/commands/command.py b/evennia/commands/command.py index 8dbac1c3a7..f676df49bb 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -12,13 +12,13 @@ import re from django.conf import settings from django.urls import reverse from django.utils.text import slugify - from evennia.locks.lockhandler import LockHandler from evennia.utils.ansi import ANSIString from evennia.utils.evtable import EvTable from evennia.utils.utils import fill, is_iter, lazy_property, make_iter CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES +_RE_CMD_LOCKFUNC_IN_LOCKSTRING = re.compile(r"(^|;|\s)cmd\:\w+", re.DOTALL) class InterruptCommand(Exception): @@ -74,7 +74,7 @@ def _init_command(cls, **kwargs): if not hasattr(cls, "locks"): # default if one forgets to define completely cls.locks = "cmd:all()" - if "cmd:" not in cls.locks: + if not _RE_CMD_LOCKFUNC_IN_LOCKSTRING.search(cls.locks): cls.locks = "cmd:all();" + cls.locks for lockstring in cls.locks.split(";"): if lockstring and ":" not in lockstring: @@ -575,7 +575,7 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th ex. :: - url(r'characters/(?P[\w\d\-]+)/(?P[0-9]+)/$', + url(r'characters/(?P[\\w\\d\\-]+)/(?P[0-9]+)/$', CharDetailView.as_view(), name='character-detail') If no View has been created and defined in urls.py, returns an diff --git a/evennia/commands/tests.py b/evennia/commands/tests.py index 10eb5143a7..ea9c954b2e 100644 --- a/evennia/commands/tests.py +++ b/evennia/commands/tests.py @@ -4,7 +4,6 @@ Unit testing for the Command system itself. """ from django.test import override_settings - from evennia.commands import cmdparser from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command @@ -991,9 +990,8 @@ class TestOptionTransferReplace(TestCase): import sys -from twisted.trial.unittest import TestCase as TwistedTestCase - from evennia.commands import cmdhandler +from twisted.trial.unittest import TestCase as TwistedTestCase def _mockdelay(time, func, *args, **kwargs): @@ -1307,3 +1305,24 @@ class TestIssue3090(BaseEvenniaTest): self.assertEqual(result[3], 8) self.assertEqual(result[4], 1.0) self.assertEqual(result[5], "smile at") + + +class _TestCmd1(Command): + key = "testcmd" + locks = "usecmd:false()" + + def func(): + pass + + +class TestIssue3643(BaseEvenniaTest): + """ + Commands with a 'cmd:' anywhere in its string, even `funccmd:` is assumed to + be a cmd: type lock, meaning it will not auto-insert `cmd:all()` into the + lockstring as intended. + + """ + + def test_issue_3643(self): + cmd = _TestCmd1() + self.assertEqual(cmd.locks, "cmd:all();usecmd:false()")