Skip to content

Commit e56d1ff

Browse files
committed
Updated load/unload/reload of plugins to make sure the name is alphanumeric.
1 parent b711b76 commit e56d1ff

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

addons/source-python/packages/source-python/core/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ../_core/command.py
1+
# ../core/command.py
22

33
"""Registers the "sp" command and all of its sub-commands."""
44

addons/source-python/packages/source-python/plugins/command.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ def print_help(self, message=''):
251251

252252
def load_plugin(self, plugin_name):
253253
"""Load a plugin by name."""
254+
# Is the given plugin name a proper name?
255+
if not plugin_name.isalnum():
256+
257+
# Send a message that the given name is invalid
258+
self.logger.log_message(self.prefix + self.translations[
259+
'Invalid Name'].get_string(plugin=plugin_name))
260+
261+
# No need to go further
262+
return
263+
254264
# Is the plugin already loaded?
255265
if plugin_name in self.manager:
256266

@@ -283,6 +293,16 @@ def load_plugin(self, plugin_name):
283293

284294
def unload_plugin(self, plugin_name):
285295
"""Unload a plugin by name."""
296+
# Is the given plugin name a proper name?
297+
if not plugin_name.isalnum():
298+
299+
# Send a message that the given name is invalid
300+
self.logger.log_message(self.prefix + self.translations[
301+
'Invalid Name'].get_string(plugin=plugin_name))
302+
303+
# No need to go further
304+
return
305+
286306
# Is the plugin loaded?
287307
if plugin_name not in self.manager:
288308

@@ -305,6 +325,16 @@ def unload_plugin(self, plugin_name):
305325

306326
def reload_plugin(self, plugin_name):
307327
"""Reload a plugin by name."""
328+
# Is the given plugin name a proper name?
329+
if not plugin_name.isalnum():
330+
331+
# Send a message that the given name is invalid
332+
self.logger.log_message(self.prefix + self.translations[
333+
'Invalid Name'].get_string(plugin=plugin_name))
334+
335+
# No need to go further
336+
return
337+
308338
# Unload the plugin
309339
self.unload_plugin(plugin_name)
310340

resource/source-python/translations/_core/plugin_strings.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[Invalid Name]
2+
en = "Given plugin name '$plugin' is invalid. Plugin names must be alphanumeric."
3+
14
[Loading]
25
en = "Loading plugin '$plugin'..."
36
de = "Lade Plugin '$plugin'..."

0 commit comments

Comments
 (0)