mirror of
https://github.com/evennia/evennia.git
synced 2026-04-18 06:09:06 +02:00
Uses utils.dbref() for dbref validation.
This commit is contained in:
parent
39fa8dacdf
commit
0b38de0057
1 changed files with 18 additions and 11 deletions
|
|
@ -13,6 +13,7 @@ from evennia.utils.utils import (
|
||||||
class_from_module,
|
class_from_module,
|
||||||
get_all_typeclasses,
|
get_all_typeclasses,
|
||||||
variable_from_module,
|
variable_from_module,
|
||||||
|
dbref,
|
||||||
)
|
)
|
||||||
from evennia.utils.eveditor import EvEditor
|
from evennia.utils.eveditor import EvEditor
|
||||||
from evennia.utils.evmore import EvMore
|
from evennia.utils.evmore import EvMore
|
||||||
|
|
@ -2792,19 +2793,25 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
||||||
low, high = 1, ObjectDB.objects.all().order_by("-id").first().id
|
low, high = 1, ObjectDB.objects.all().order_by("-id").first().id
|
||||||
|
|
||||||
if self.rhs:
|
if self.rhs:
|
||||||
# Check that rhs is either a valid dbref or dbref range
|
|
||||||
try:
|
try:
|
||||||
# Get rid of # signs, split on hyphen or space and cast all to int.
|
# Check that rhs is either a valid dbref or dbref range
|
||||||
# Then sort by number to get the lowest and highest values
|
bounds = tuple(sorted(dbref(x, False) for x in re.split('[-\s]+', self.rhs.strip())))
|
||||||
# comprising the bounds.
|
|
||||||
bounds = sorted(int(x) for x in re.split('[-\s]+', self.rhs.strip().replace('#', '')))
|
# dbref() will return either a valid int or None
|
||||||
except ValueError:
|
assert bounds
|
||||||
|
# None should not exist in the bounds list
|
||||||
|
assert None not in bounds
|
||||||
|
|
||||||
|
low = bounds[0]
|
||||||
|
if len(bounds) > 1:
|
||||||
|
high = bounds[-1]
|
||||||
|
|
||||||
|
except AssertionError:
|
||||||
caller.msg("Invalid dbref range provided (not a number).")
|
caller.msg("Invalid dbref range provided (not a number).")
|
||||||
return
|
return
|
||||||
|
except IndexError as e:
|
||||||
low = bounds[0]
|
logger.log_err(f"{self.__class__.__name__}: Error parsing upper and lower bounds of query.")
|
||||||
if len(bounds) > 1:
|
logger.log_trace(e)
|
||||||
high = bounds[-1]
|
|
||||||
|
|
||||||
low = min(low, high)
|
low = min(low, high)
|
||||||
high = max(low, high)
|
high = max(low, high)
|
||||||
|
|
@ -2901,7 +2908,7 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
||||||
filtered_qs = result_qs.filter(id__in=obj_ids).distinct()
|
filtered_qs = result_qs.filter(id__in=obj_ids).distinct()
|
||||||
nresults = filtered_qs.count()
|
nresults = filtered_qs.count()
|
||||||
|
|
||||||
# Keep using iterator to minimize memory ballooning
|
# Use iterator again to minimize memory ballooning
|
||||||
results = filtered_qs.iterator()
|
results = filtered_qs.iterator()
|
||||||
|
|
||||||
# still results after type filtering?
|
# still results after type filtering?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue