diff --git a/src/BizHawk.Common/Extensions/StringExtensions.cs b/src/BizHawk.Common/Extensions/StringExtensions.cs index 3855b678c3..400ec5dc8e 100644 --- a/src/BizHawk.Common/Extensions/StringExtensions.cs +++ b/src/BizHawk.Common/Extensions/StringExtensions.cs @@ -43,6 +43,10 @@ namespace BizHawk.Common.StringExtensions public static bool In(this string str, params string[] options) => options.Any(opt => string.Equals(opt, str, StringComparison.OrdinalIgnoreCase)); + /// a copy of with all characters outside [0-9A-Za-z] removed + public static string OnlyAlphanumeric(this string raw) + => string.Concat(raw.Where(static c => c is (>= '0' and <= '9') or (>= 'A' and <= 'Z') or (>= 'a' and <= 'z'))); + /// /// with the first char removed, or /// the original if the first char of is not diff --git a/src/BizHawk.Common/VersionInfo.cs b/src/BizHawk.Common/VersionInfo.cs index f3214d61ae..e63e74d356 100644 --- a/src/BizHawk.Common/VersionInfo.cs +++ b/src/BizHawk.Common/VersionInfo.cs @@ -39,7 +39,9 @@ namespace BizHawk.Common CustomBuildString = lines[0]; } } - UserAgentEscaped = $"BizHawk/{MainVersion}{(DeveloperBuild ? "-dev" : string.Empty)}"; + UserAgentEscaped = $"{ + (string.IsNullOrWhiteSpace(CustomBuildString) ? "EmuHawk" : CustomBuildString!.OnlyAlphanumeric()) + }/{MainVersion}{(DeveloperBuild ? "-dev" : string.Empty)}"; } public static (string Label, string TargetURI) GetGitCommitLink()