fix: disallows the use of specified strings in the name argument for these commands

This commit is contained in:
Duncan Brown authored and Julian Murgia committed 2022-08-24 22:36:15 +02:00
1 parent 57f7d945ce
commit 5be887cdf5
3 files changed
+48 -3

No files matched your search

@@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryAddCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
@@ -27,13 +30,15 @@ func validate(arguments: Array):
if not .validate(arguments):
return false
if arguments[0].begins_with("i/"):
for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot start with 'i/'."
% [get_command_name(), arguments[0]]
"[%s]: invalid item name. Item name %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false
return true
@@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryRemoveCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
@@ -22,6 +25,23 @@ func configure() -> ESCCommandArgumentDescriptor:
)
# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false
for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false
return true
# Run the command
func run(command_params: Array) -> int:
escoria.inventory_manager.remove_item(command_params[0])
@@ -16,6 +16,9 @@ extends ESCBaseCommand
class_name SetGlobalCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
@@ -25,6 +28,23 @@ func configure() -> ESCCommandArgumentDescriptor:
)
# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false
for s in ILLEGAL_STRINGS:
if s in arguments[0]:
escoria.logger.error(
self,
"[%s]: invalid global variable. Global variable %s cannot contain the string '%s'."
% [get_command_name(), arguments[0], s]
)
return false
return true
# Run the command
func run(command_params: Array) -> int:
escoria.globals_manager.set_global(