Skip to content

Commit 10e1669

Browse files
Copilotkirre-bylund
andcommitted
Add semver validation for game_version command line argument
Co-authored-by: kirre-bylund <4068377+kirre-bylund@users.noreply.github.com>
1 parent 472db34 commit 10e1669

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Runtime/Game/Resources/LootLockerConfig.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Text.RegularExpressions;
34
#if UNITY_EDITOR
45
using UnityEditor;
56
using UnityEditor.PackageManager;
@@ -94,7 +95,15 @@ private void CheckForSettingOverrides()
9495
}
9596
else if (args[i] == "-gameversion")
9697
{
97-
game_version = args[i + 1];
98+
string versionValue = args[i + 1];
99+
if (IsSemverString(versionValue))
100+
{
101+
game_version = versionValue;
102+
}
103+
else
104+
{
105+
Debug.LogWarning($"Invalid game version format: '{versionValue}'. Game version must follow Semantic Versioning pattern X.Y.Z.B (e.g., 1.0.0 or 1.0.0.0). See https://docs.lootlocker.com/the-basics/core-concepts/glossary#game-version");
106+
}
98107
}
99108
else if (args[i] == "-timeout")
100109
{
@@ -149,6 +158,11 @@ private void CheckForSettingOverrides()
149158
#endif
150159
}
151160

161+
private static bool IsSemverString(string str)
162+
{
163+
return Regex.IsMatch(str, @"^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?$");
164+
}
165+
152166
#if UNITY_EDITOR
153167
[InitializeOnLoadMethod]
154168
static void CreateConfigFile()

0 commit comments

Comments
 (0)