Skip to content

Commit bc80525

Browse files
committed
fix(RESTConnector): Properly parse version from operating system info
1 parent 50b4016 commit bc80525

File tree

4 files changed

+19
-1456
lines changed

4 files changed

+19
-1456
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ Docs/publishing-release.md.meta
7878
/Scripts/Editor/Help/
7979
/Scripts/Editor/Help.meta
8080
*/MRefBuilder.config.meta
81+
package-lock.json
82+
package-lock.json.meta

Scripts/Connection/RESTConnector.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Text;
2727
using UnityEngine;
2828
using UnityEngine.Networking;
29+
using System.Text.RegularExpressions;
2930

3031
#if !NETFX_CORE
3132
using System.Net;
@@ -376,14 +377,23 @@ private void AddHeaders(Dictionary<string, string> headers)
376377
}
377378

378379
string osInfo = SystemInfo.operatingSystem;
379-
int osIndex = osInfo.IndexOf(" ");
380-
string os = osInfo.Substring(0, osIndex).Replace(" ", "");
381-
string osVersion = osInfo.Substring(osIndex).Replace(" ", "");
380+
Regex pattern = new Regex("\\d+(\\.\\d+)+");
381+
Match m = pattern.Match(osInfo);
382+
string osVersion = m.Value;
383+
string os = osInfo.Replace(osVersion, "").Replace(" ", "");
384+
if(os.Contains("("))
385+
{
386+
os.Replace("(", "");
387+
}
388+
if (os.Contains(")"))
389+
{
390+
os.Replace(")", "");
391+
}
382392
headers.Add("User-Agent",
383393
string.Format(
384394
"{0} {1} {2} {3}",
385395
Constants.String.Version,
386-
os,
396+
os,
387397
osVersion,
388398
Application.unityVersion
389399
));

Scripts/Utilities/Utility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,9 @@ public static string CreateAuthorization(string username, string password)
12711271
#region Has Bad First Character
12721272
public static bool HasBadFirstOrLastCharacter(string value)
12731273
{
1274+
if (string.IsNullOrEmpty(value))
1275+
return false;
1276+
12741277
return value.StartsWith("{") || value.StartsWith("\"") || value.EndsWith("}") || value.EndsWith("\"");
12751278
}
12761279
#endregion

0 commit comments

Comments
 (0)