Skip to content

Commit ab07a4e

Browse files
committed
remove uint from modrefere check too
1 parent 9388d98 commit ab07a4e

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

src/EawModinfo.Tests/ModinfoValidatorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ public static IEnumerable<object[]> GetModReferences()
246246
yield return [new ModReference { Identifier = "123456", Type = ModType.Default }, false];
247247
yield return [new ModReference { Identifier = "123456", Type = ModType.Workshops }, false];
248248
yield return [new ModReference { Identifier = "blabla", Type = ModType.Virtual }, false];
249+
yield return [new ModReference { Identifier = ulong.MaxValue.ToString(), Type = ModType.Workshops }, false];
250+
yield return [new ModReference { Identifier = "1" + ulong.MaxValue, Type = ModType.Workshops }, false];
251+
yield return [new ModReference { Identifier = "abcdef", Type = ModType.Workshops }, false];
249252
}
250253

251254
public static IEnumerable<object[]> GetInvalidModReferences()
@@ -261,12 +264,10 @@ public static IEnumerable<object[]> GetInvalidModReferences()
261264
];
262265
yield return [new ModReference { Identifier = null!, Type = ModType.Workshops }, true];
263266
yield return [new ModReference { Identifier = null!, Type = ModType.Virtual }, true];
267+
yield return [new ModReference { Identifier = null!, Type = ModType.Default }, true];
264268
yield return [new ModReference { Identifier = string.Empty, Type = ModType.Default }, true];
265269
yield return [new ModReference { Identifier = string.Empty, Type = ModType.Workshops }, true];
266270
yield return [new ModReference { Identifier = string.Empty, Type = ModType.Virtual }, true];
267-
yield return [new ModReference { Identifier = "-1", Type = ModType.Workshops }, true];
268-
yield return [new ModReference { Identifier = "0", Type = ModType.Workshops }, true];
269-
yield return [new ModReference { Identifier = "12921908098098098309481234", Type = ModType.Workshops }, true];
270271
yield return [new ModReference { Identifier = "1234", Type = (ModType) 0xff }, true];
271272
}
272273

src/EawModinfo/Utilities/ModinfoValidator.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,16 @@ private static bool ContainsInvalidCharacter(ReadOnlySpan<char> value)
8585

8686
/// <summary>
8787
/// Validates an <see cref="IModReference"/> data. Throws an <see cref="ModinfoException"/> when validation failed.
88+
/// That is when the identifier is <see langword="null"/> or an empty string.
8889
/// </summary>
89-
/// <remarks>
90-
/// When <see cref="IModReference.Type"/> is <see cref="ModType.Workshops"/>:
91-
/// <see cref="IModReference.Identifier"/> must parse into an <see cref="uint"/> larger than 0.
92-
/// <br></br>
93-
/// The validator will not check for if the <see cref="IModReference.Identifier"/> is a valid file system path.
94-
/// </remarks>
9590
/// <param name="modReference">The data to validate.</param>
9691
/// <exception cref="ModinfoException">The validation failed.</exception>
9792
public static void Validate(this IModReference modReference)
9893
{
9994
if (string.IsNullOrEmpty(modReference.Identifier))
10095
throw new ModinfoException("Mod-Reference data is invalid: Identifier is missing.");
101-
switch (modReference.Type)
102-
{
103-
case ModType.Workshops:
104-
ValidateSteamId(modReference.Identifier, $"Mod-Reference data is invalid: '{modReference}'");
105-
break;
106-
case ModType.Default:
107-
case ModType.Virtual:
108-
break;
109-
default:
110-
throw new ModinfoException($"ERROR: Unknown ModType! ({modReference.Type})");
111-
}
96+
if (!Enum.IsDefined(typeof(ModType), modReference.Type))
97+
throw new ModinfoException("Mod-Reference data is invalid: ModType not valid.");
11298
}
11399

114100
/// <summary>
@@ -154,7 +140,7 @@ private static (bool Valid, string Error) ValidateSteamId(string data)
154140
if (data[0] == '0')
155141
return (false, "Workshops ID cannot have leading zeros.");
156142
if (!ulong.TryParse(data, NumberStyles.None, CultureInfo.InvariantCulture, out var id))
157-
return (false, "Workshops ID must be an uint number.");
143+
return (false, "Workshops ID must be an ulong number.");
158144
if (id == 0)
159145
return (false, "Workshops ID cannot be 0.");
160146
return (true, string.Empty);

0 commit comments

Comments
 (0)