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

This commit is contained in:
Duncan Brown
2022-08-23 20:32:46 -04:00
committed by Julian Murgia
parent 57f7d945ce
commit 5be887cdf5
3 changed files with 52 additions and 7 deletions

View File

@@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryAddCommand class_name InventoryAddCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command # Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor: func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new( return ESCCommandArgumentDescriptor.new(
@@ -27,13 +30,15 @@ func validate(arguments: Array):
if not .validate(arguments): if not .validate(arguments):
return false return false
if arguments[0].begins_with("i/"): for s in ILLEGAL_STRINGS:
escoria.logger.error( if s in arguments[0]:
self, escoria.logger.error(
"[%s]: invalid item name. Item name %s cannot start with 'i/'." self,
% [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 false
return true return true

View File

@@ -13,6 +13,9 @@ extends ESCBaseCommand
class_name InventoryRemoveCommand class_name InventoryRemoveCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command # Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor: func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new( 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 # Run the command
func run(command_params: Array) -> int: func run(command_params: Array) -> int:
escoria.inventory_manager.remove_item(command_params[0]) escoria.inventory_manager.remove_item(command_params[0])

View File

@@ -16,6 +16,9 @@ extends ESCBaseCommand
class_name SetGlobalCommand class_name SetGlobalCommand
const ILLEGAL_STRINGS = ["/"]
# Return the descriptor of the arguments of this command # Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor: func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new( 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 # Run the command
func run(command_params: Array) -> int: func run(command_params: Array) -> int:
escoria.globals_manager.set_global( escoria.globals_manager.set_global(