Fix case if using string "call:" anywhere in locktype tricked Command to not use a fallback. Resolve #3643.

This commit is contained in:
Griatch 2024-10-21 22:01:35 +02:00
parent 04374e5392
commit 1360f17202
4 changed files with 33 additions and 6 deletions

View file

@ -15,6 +15,8 @@
- [Fix][pull3640]: Typo fixes for conjugate verbs (aMiss-aWry) - [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][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][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][pull3576]: Rework doc for [Pycharm howto][doc-pycharm]
- Docs updates: feykrh, Griatch - Docs updates: feykrh, Griatch
@ -29,6 +31,7 @@
[pull3647]: https://github.com/evennia/evennia/pull/3647 [pull3647]: https://github.com/evennia/evennia/pull/3647
[pull3635]: https://github.com/evennia/evennia/pull/3635 [pull3635]: https://github.com/evennia/evennia/pull/3635
[issue3627]: https://github.com/evennia/evennia/issues/3627 [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 [doc-pycharm]: https://www.evennia.com/docs/latest/Coding/Setting-up-PyCharm.html
## Evennia 4.4.1 ## Evennia 4.4.1

View file

@ -14,6 +14,9 @@
- [Fix][pull3645]: Correct `character_creator` contrib's error return (InspectorCaracal) - [Fix][pull3645]: Correct `character_creator` contrib's error return (InspectorCaracal)
- [Fix][pull3640]: Typo fixes for conjugate verbs (aMiss-aWry) - [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][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][pull3576]: Rework doc for [Pycharm howto][doc-pycharm]
- Docs updates: feykrh, Griatch - Docs updates: feykrh, Griatch
@ -27,6 +30,8 @@
[pull3640]: https://github.com/evennia/evennia/pull/3640 [pull3640]: https://github.com/evennia/evennia/pull/3640
[pull3647]: https://github.com/evennia/evennia/pull/3647 [pull3647]: https://github.com/evennia/evennia/pull/3647
[pull3635]: https://github.com/evennia/evennia/pull/3635 [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 [doc-pycharm]: https://www.evennia.com/docs/latest/Coding/Setting-up-PyCharm.html
## Evennia 4.4.1 ## Evennia 4.4.1

View file

@ -12,13 +12,13 @@ import re
from django.conf import settings from django.conf import settings
from django.urls import reverse from django.urls import reverse
from django.utils.text import slugify from django.utils.text import slugify
from evennia.locks.lockhandler import LockHandler from evennia.locks.lockhandler import LockHandler
from evennia.utils.ansi import ANSIString from evennia.utils.ansi import ANSIString
from evennia.utils.evtable import EvTable from evennia.utils.evtable import EvTable
from evennia.utils.utils import fill, is_iter, lazy_property, make_iter from evennia.utils.utils import fill, is_iter, lazy_property, make_iter
CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES
_RE_CMD_LOCKFUNC_IN_LOCKSTRING = re.compile(r"(^|;|\s)cmd\:\w+", re.DOTALL)
class InterruptCommand(Exception): class InterruptCommand(Exception):
@ -74,7 +74,7 @@ def _init_command(cls, **kwargs):
if not hasattr(cls, "locks"): if not hasattr(cls, "locks"):
# default if one forgets to define completely # default if one forgets to define completely
cls.locks = "cmd:all()" 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 cls.locks = "cmd:all();" + cls.locks
for lockstring in cls.locks.split(";"): for lockstring in cls.locks.split(";"):
if lockstring and ":" not in lockstring: if lockstring and ":" not in lockstring:
@ -575,7 +575,7 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th
ex. ex.
:: ::
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$', url(r'characters/(?P<slug>[\\w\\d\\-]+)/(?P<pk>[0-9]+)/$',
CharDetailView.as_view(), name='character-detail') CharDetailView.as_view(), name='character-detail')
If no View has been created and defined in urls.py, returns an If no View has been created and defined in urls.py, returns an

View file

@ -4,7 +4,6 @@ Unit testing for the Command system itself.
""" """
from django.test import override_settings from django.test import override_settings
from evennia.commands import cmdparser from evennia.commands import cmdparser
from evennia.commands.cmdset import CmdSet from evennia.commands.cmdset import CmdSet
from evennia.commands.command import Command from evennia.commands.command import Command
@ -991,9 +990,8 @@ class TestOptionTransferReplace(TestCase):
import sys import sys
from twisted.trial.unittest import TestCase as TwistedTestCase
from evennia.commands import cmdhandler from evennia.commands import cmdhandler
from twisted.trial.unittest import TestCase as TwistedTestCase
def _mockdelay(time, func, *args, **kwargs): def _mockdelay(time, func, *args, **kwargs):
@ -1307,3 +1305,24 @@ class TestIssue3090(BaseEvenniaTest):
self.assertEqual(result[3], 8) self.assertEqual(result[3], 8)
self.assertEqual(result[4], 1.0) self.assertEqual(result[4], 1.0)
self.assertEqual(result[5], "smile at") 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()")