From 9dfd69e49ded639bb79c52cd909900144b85ae42 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 24 Nov 2021 14:58:35 +0100 Subject: [PATCH] [unity] Fixed json files starting with array brackets not being detected as json. Closes #1992. --- .../Asset Types/SkeletonDataCompatibility.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs index 6404a1357..b35fa48be 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs @@ -96,8 +96,7 @@ namespace Spine.Unity { if (hasBinaryExtension) { problemDescription = string.Format("Failed to read '{0}'. Extension is '.skel.bytes' but content looks like a '.json' file.\n" + "Did you choose the wrong extension upon export?\n", asset.name); - } - else { + } else { problemDescription = string.Format("Failed to read '{0}'. Extension is '.json' but content looks like binary 'skel.bytes' file.\n" + "Did you choose the wrong extension upon export?\n", asset.name); } @@ -110,19 +109,16 @@ namespace Spine.Unity { using (var memStream = new MemoryStream(asset.bytes)) { fileVersion.rawVersion = SkeletonBinary.GetVersionString(memStream); } - } - catch (System.Exception e) { + } catch (System.Exception e) { problemDescription = string.Format("Failed to read '{0}'. It is likely not a binary Spine SkeletonData file.\n{1}", asset.name, e); isSpineSkeletonData = false; return null; } - } - else { + } else { Match match = jsonVersionRegex.Match(asset.text); if (match != null) { fileVersion.rawVersion = match.Groups[1].Value; - } - else { + } else { object obj = Json.Deserialize(new StringReader(asset.text)); if (obj == null) { problemDescription = string.Format("'{0}' is not valid JSON.", asset.name); @@ -156,8 +152,7 @@ namespace Spine.Unity { try { fileVersion.version = new[]{ int.Parse(versionSplit[0], CultureInfo.InvariantCulture), int.Parse(versionSplit[1], CultureInfo.InvariantCulture) }; - } - catch (System.Exception e) { + } catch (System.Exception e) { problemDescription = string.Format("Failed to read version info at skeleton '{0}'. It is likely not a valid Spine SkeletonData file.\n{1}", asset.name, e); isSpineSkeletonData = false; return null; @@ -179,9 +174,11 @@ namespace Spine.Unity { if (char.IsWhiteSpace(c)) continue; if (!openingBraceFound) { - if (c == '{') openingBraceFound = true; + if (c == '{' || c == '[') openingBraceFound = true; else return false; - } else + } else if (c == '{' || c == '[' || c == ']' || c == '}' || c == ',') + continue; + else return c == '"'; } return true;