diff --git a/src/BizHawk.Emulation.Common/Database/FirmwareDatabase.cs b/src/BizHawk.Emulation.Common/Database/FirmwareDatabase.cs index f385711397..ddb80af2da 100644 --- a/src/BizHawk.Emulation.Common/Database/FirmwareDatabase.cs +++ b/src/BizHawk.Emulation.Common/Database/FirmwareDatabase.cs @@ -47,8 +47,6 @@ namespace BizHawk.Emulation.Common additionalInfo: additionalInfo, isBad: isBad); - // make sure id doesn't have a space, it is stored in the (space delimited) movie header! - void Option(string systemId, string id, in FirmwareFile ff, FirmwareOptionStatus status = FirmwareOptionStatus.Acceptable) { var option = new FirmwareOption(new(systemId, id), ff.Hash, ff.Size, ff.IsBad ? FirmwareOptionStatus.Bad : status); diff --git a/src/BizHawk.Emulation.Common/Database/FirmwareID.cs b/src/BizHawk.Emulation.Common/Database/FirmwareID.cs index fb259f4904..70173dc9c4 100644 --- a/src/BizHawk.Emulation.Common/Database/FirmwareID.cs +++ b/src/BizHawk.Emulation.Common/Database/FirmwareID.cs @@ -1,3 +1,6 @@ +using System; +using System.Linq; + namespace BizHawk.Emulation.Common { public readonly struct FirmwareID @@ -16,6 +19,11 @@ namespace BizHawk.Emulation.Common public FirmwareID(string system, string firmware) { + static bool IsAllowedCharacter(char c) + => c is '-' or (>= '0' and <= '9') or (>= 'A' and <= 'Z') or '_' or (>= 'a' and <= 'z'); + const string ERR_MSG_INVALID_CHAR = "FWIDs must match /[-0-9A-Z_a-z]+/"; + if (!system.All(IsAllowedCharacter)) throw new ArgumentOutOfRangeException(paramName: system, actualValue: system, message: ERR_MSG_INVALID_CHAR); + if (!firmware.All(IsAllowedCharacter)) throw new ArgumentOutOfRangeException(paramName: firmware, actualValue: firmware, message: ERR_MSG_INVALID_CHAR); System = system; Firmware = firmware; }