Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade semver validation to disallow leading zeros and overly long versions #71

Merged
merged 3 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions addons/mod_loader/mod_loader_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ static func log_debug_json_print(message: String, json_printable, mod_name: Stri


static func _loader_log(message: String, mod_name: String, log_type: String = "info") -> void:
var ignored_arg := get_cmd_line_arg_value("--log-ignore")
var ignored_names: Array = str2var(ignored_arg)
if ignored_names and mod_name in ignored_names:
if is_mod_name_ignored(mod_name):
return

var date := "%s " % get_date_time_string()
Expand Down Expand Up @@ -89,6 +87,16 @@ static func _loader_log(message: String, mod_name: String, log_type: String = "i
_write_to_log_file(log_message)


static func is_mod_name_ignored(mod_name: String) -> bool:
var ignored_arg := get_cmd_line_arg_value("--log-ignore")

if not ignored_arg == "":
var ignored_names: Array = ignored_arg.split(",")
if mod_name in ignored_names:
return true
return false


static func _write_to_log_file(log_entry: String) -> void:
var log_file := File.new()

Expand Down
19 changes: 14 additions & 5 deletions addons/mod_loader/mod_manifest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Resource
# Stores and validates contents of the manifest set by the user
class_name ModManifest

const LOG_NAME := "ModLoader:ModManifest"

# Mod name.
# Validated by [method is_name_or_namespace_valid]
Expand Down Expand Up @@ -95,7 +96,7 @@ func get_package_id() -> String:

# A valid namespace may only use letters (any case), numbers and underscores
# and has to be longer than 3 characters
# /^[a-zA-Z0-9_]{3,}$/
# a-z A-Z 0-9 _ (longer than 3 characters)
static func is_name_or_namespace_valid(name: String) -> bool:
var re := RegEx.new()
re.compile("^[a-zA-Z0-9_]*$") # alphanumeric and _
Expand All @@ -114,14 +115,22 @@ static func is_name_or_namespace_valid(name: String) -> bool:

# A valid semantic version should follow this format: {mayor}.{minor}.{patch}
# reference https://semver.org/ for details
# /^[0-9]+\\.[0-9]+\\.[0-9]+$/
# {0-9}.{0-9}.{0-9} (no leading 0, shorter than 16 characters total)
static func is_semver_valid(version_number: String) -> bool:
var re := RegEx.new()
re.compile("^[0-9]+\\.[0-9]+\\.[0-9]+$")
re.compile("^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$")

if re.search(version_number) == null:
printerr('Invalid semantic version: "%s". ' +
'You may only use numbers and periods in this format {mayor}.{minor}.{patch}' % version_number)
ModLoaderUtils.log_fatal('Invalid semantic version: "%s". ' +
'You may only use numbers without leading zero and periods following this format {mayor}.{minor}.{patch}' % version_number,
LOG_NAME
)
return false

if version_number.length() > 16:
ModLoaderUtils.log_fatal('Invalid semantic version: "%s". ' +
'Version number must be shorter than 16 characters.', LOG_NAME
)
return false

return true
Expand Down